Refactored the detectTargets method into InputUtil