Fix bug caused by renaming

Fixed a bug caused by renaming an index variable from 'n' to 'i'
because some variables were forgotten.