refactoring for easier mocking