Change table.getn(t) to #t which is the correct form for latest versions of Lua