Fix potential crash with beds

Fix ported from opentibia/server, see
https://github.com/opentibia/server/commit/9a8c5cace1180ba2e69899526c599f77249c377e
for details.

This commit also reduces the memory footprint of beds.