Optimized the detection process