It turns out it actually did work before;  I was just doing it wrong.
This commit fixes a few minor bugs in the new code.