add protection to loop