refactor fetch logic in map.js