detect function in a better way