Added more tests and bug fixes