how the loop detector working