modify map and reduce; add aid function