Using reduce instead of inject