detect function