moving code from map.js to mainjs.js