Added accurate cycle detection.

[Delivers #57445434]
Self-review.