finish detect code