Fix bugs in unit tests