fix references and detect unknown type