updated code for detection