At cycle detection, replace condition in loop by a while(true), thus making the loop faster.