Refactoring to make it testable