Add more tests and fix few bugs