refactoring for easier testing