Replace sum() with reduce().