avoid using [] operator in the for loop and change variable names

I have changed the for loop to avoid using [] operator.
And also I have changed several variants name.