Use each_with_object instead of reduce

It's clearer and slightly faster.