Various fixes to suggestions by @mikehearn and @instagibbs