adding more unit tests and refactoring