Rewrite _detectCycle