Fix loop detection.