Fixed a few bugs causing test failures