Add basic cycle detection