some Lua code reorganization