Fix bugs causing tests to fail