Fix possible endless loop