Using each_with_object instead of reduce