use reduce instead of map