Fixed some bugs in unit tests