Fix undefined method `ref' for nil:NilClass  for bad headers