Fixed some minor bugs uncovered by the new test suite