Refactor map generation