Combining a map operation with reduce