modularize heightmap code