changed the looping index logic.