fix cycle detection