pairs for Lua 5.1, code cleanup