Fixed a couple of bugs I introduced (really need to start unit testing this stuff..)