refactored method for testability