Code refactored and Unit Tests Added