refactored out duplicate functions to a helper service.