This can be rewritten to use `each_with_object`.