adding more unit tests and refactoring code