Haha. It may not be optimal, but it works, and that’s the most important thing.
Btw, I had to do a similar thing in a recent prototype. Here’s how I solved it:
local empty = {}
function M.get_map_cell(map, x, y, z)
return ((map.layers[z] or empty)[x] or empty)[y]
end