Heh, this was stolen directly from @vieux, since I've included his PR here to make these changes simpler.  Also, he hasn't cleared any of this in theory, let alone practice, so I'm not too keen on doing too much more work on it unless it gets reviewed and general acceptance. :)