Added more tests and fixed bugs