added unit tests and refactoring