Refactoring js/map.js