refactored the code and added one test class