Refactored map generation code and data structure