Minor changes to improve patch-ability.

Can this be merged back into the Hg mainline from the github mirror?
This patch has no physical effect, it just tweaks functions to make them patch-able without problems.