refactoring to make code testable