Fix some bugs I hadn't noticed previously