Fix endless loop