Refactored code. Tests still passing.