Refactor map generation routines