detection looping code