DISTDIR = uwobo-$(VERSION)
 DISTTARBALL = $(DISTDIR).tar.gz
 REQUIRES = http gdome2 gdome2-xslt pcre unix helm-registry
-COMMONOPTS = -package "$(REQUIRES)" -pp camlp4o
+COMMONOPTS = -package "$(REQUIRES)" -pp camlp4o -rectypes
 ifeq ($(origin OCAMLPATH), undefined)
 OCAMLFIND = OCAMLPATH=../../components/METAS ocamlfind
 else
 
         let xmluri = req#param "xmluri" in
         let keys = Pcre.split ~pat:"," (req#param "keys") in
         (* notation: "local" parameters are those defined on a per-stylesheet
-        pasis (i.e. param.key.param=value), "global" parameters are those
+        basis (i.e. param.key.param=value), "global" parameters are those
         defined for all stylesheets (i.e. param.param=value) *)
         let (user_params, props) = parse_apply_params req#params in
        let profile_params =
 
   let (p_stylesheets,last_stylesheet) = styles#get keys props logger in
   logger#log `Debug "Creating input document ...";
   let intermediate_results_seqno = ref 0 in
-  let result = (* Gdome.document *)
+  let result () = (* Gdome.document *)
     List.fold_left
       (fun source (key, stylesheet) ->
         logger#log `Debug (sprintf "Applying stylesheet %s ..." key);
       input
       p_stylesheets
   in
+  let p_last_stylesheet = snd (List.hd (List.rev p_stylesheets)) in
+  ((fun outchan ->                              (* serialization function *)
+      let result = result () in
     (* add error and debugging messages to result document *)
-  add_msgs ~errormode ~debugmode ~msgs:veillogger#msgs result;
+      add_msgs ~errormode ~debugmode ~msgs:veillogger#msgs result;
 (*
   (* DEBUGGING *)
   add_msgs
     ~msgs:[LibXsltErrorMsg "error1"; LibXsltDebugMsg "debug1"]
     result;
 *)
-  let p_last_stylesheet = snd (List.hd (List.rev p_stylesheets)) in
-  ((fun outchan ->                              (* serialization function *)
       Gdome_xslt.saveResultToChannel ~outchan ~result
         ~stylesheet:p_last_stylesheet),
    (get_property "media-type" last_stylesheet), (* media-type *)
    (get_property "encoding" last_stylesheet))   (* encoding *)
-