Bulk of the map logic