generic map and reduce functions working