Updated detect code