cycle detection