replaced variable i with loop_counter