refactor code to be more testable