split out map-related functions into a factory