fixed infinite looping due to reuse of i variable for index. ew.