Refactor code to be more testable.