let lookup_subst = CicUtil.lookup_subst
 ;;
 
-
 (* clean_up_meta take a metasenv and a term and make every local context
 of each occurrence of a metavariable consistent with its canonical context, 
 with respect to the hidden hipothesis *)
             l))))
       in
        if
-        (*CSC: WARNING: if we are working up to reduction (I do not think so),
-          the following test should be replaced with "all the terms in l are
-          meta-closed" *)
-        not
-         (List.exists (function Some (Cic.Meta _) -> true | _ -> false ) l)
+         List.exists
+          (function
+              Some t -> CicUtil.is_meta_closed (apply_subst subst t)
+            | None -> true) l
        then
-        raise (MetaSubstFailure msg)
-       else
         raise (Uncertain msg)
+       else
+        raise (MetaSubstFailure msg)
    in
    let (metasenv, subst) = restrict subst !to_be_restricted metasenv in
     res, metasenv, subst
 let fppsubst ppf subst = fpp_gen ppf (ppsubst subst)
 let fppterm ppf term = fpp_gen ppf (CicPp.ppterm term)
 let fppmetasenv ppf metasenv = fpp_gen ppf (ppmetasenv [] metasenv)
-
 
     in
     (* first we check if we are in the simple case of a meta closed term *)
     let subst,metasenv,ugraph1,hetype',he,args_bo_and_ty =
-     if CicUtil.is_meta_closed hetype then
+     if CicUtil.is_meta_closed (CicMetaSubst.apply_subst subst hetype) then
       (* this optimization is to postpone fix_arity (the most common case)*)
       subst,metasenv,ugraph,hetype,he,args_bo_and_ty
      else