fixed nested for-loops using the same counter variable.