Fixed undefined variable 'i'

Fixed undefined variable 'i'