Use Reduce instead of stateful foreach