add more tests and fix a bug