refactored code.. added a test class