Refactored and Tested