Use each_with_object instead of reduce