Bug fix & Lua functions