more precise algorithm for principal instantiations