add more tests, fix bugs