Rewriting reduction with reduce instead of loop.