Use inject instead of each_with_object to maintain Ruby 1.8 compatibility