Refactored the code, and added unit test case.