refactoring to improve testability