Updated detect code again