Added more tests, fixed some bugs