This is the part that caused me to bounce this to you as a distinct branch, @jbau, rather than rolling it into a bigger branch.  I'm pretty sure this is the right thing, but not 100% sure.