Bug fixed with endless loop