2 Patches from Scott McKellar, with slight modification: