Moved all boundary checking to Lua.