use reduce instead of fold