Fixed crash and some warnings in map handling.

Fixes #728.