fixing cycle detection issue