Add cycle detection