moved away target detection and splitting to its own function