Fixed loop to fix errors