fix detect function