use sum instead of reduce in example code