changed map and reduce functions