Add some more tests and fix minor bug