Refactor ServiceDetectionTask for easier testing