Refactored code and added a simple test.