Fixed a number of bugs in the tests