fixed for loop to a more standard form based on < operator vs <= operator