Code Excercise - Refactored both code and test cases