Using `each_with_object` instead of `reduce`

This way no new object allocation is taking place. Thanks @jeremy for
the suggestion!