refactoring to be testable