Add a patch from ian@ to clean up a the code to get it closer to where
we could import it into head

Obtained from:	ian