cycle detection added