Refactored code, making it more testable.