Fix runtime errors with type references.