Added some logic for the map algorithm