Cleaning up various bugs and items from my half-asleep hacking on this
code.