Bunch 'o bugfixes.  (To be squashed in a later commit, just need a WIP)