Fixed some detection bugs