cycle detection working