Working detect code