fixed some bugs and added semifinal unit test