Corrected some bugs found when running the tests in debug mode.