Latest version of Conrad's patch, plus small fixes.