apply some of the fixes sent by Neil Hainer