fixed some bugs, added more tests