Rework map data handling to use actual objects.

Some bugs remain.