Just wondering what does i,v mean or for i,v.
In your second example it should be pairs, not ipairs. ipairs only works for arrays.
pairs
ipairs