added more tests and refactor