Fix cycle detection