Refactored code and tests.