Refactored code and added unit tests
refactored code and added unit tests