Problem 3 refactored & Tested