Added protection from endless loop