improve $ref and missing type handling