Added more tests and slight refactoring