pairs is a wrapped iterator to iterate through a table, it goes through all keys where its values is not nil.
You should use the next iterator instead of pairs since it's directly using the iterator:
for key, value in next, tbl do
instead of
for key, value in pairs(tbl) do |