Fixed some bugs, all tests passed