Fix bugs in tests