Added more error handling for Lua