reorganized mapGraph algorithm