fixed some bugs causing tests to fail or hang