add more tests and fix some bugs