Robustify lookupFamInstEnv, plus some refactoring