Solving infinite bucle