refactor map.js code