fixed possible endless loop