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 that may be of interest, but I think it'll require more work to decide.