Problem
The nested closures in find_cycle result in deep, complex control flow that is difficult to follow and maintain.
Proposed Solution
Simplify the traversal logic by either:
- Moving the traversal into a separate type
- Breaking out smaller, focused functions
- Reducing nesting levels
This would ease comprehension and make the code more maintainable.
Context