Moved the map logic to a common js file