refactored code to make it test driven development