Added more tests and refactor