fix errors in for loop