fix heuristic bug in the loop