Minor fixes from Andrew from 2012.

It seems these fixes were never merged upstream.  I cherry picked these from 0c1d3e77540441123a9b2ec77c6fd29c240d182a and 9e1ed896f2cc0843ccffb4e30ba64be413e41d02.

Note: adjacent to those commits are some others (e.g. 12d50068dd62d231cd1ddcce31d90ac180058b7c) that may be of interest, but I think it'll require more work to decide.