index for loop fix