private TEIValidator.Errors extractPreparationSteps(Document doc) throws LaudatioException, IOException, SAXException
  {
    TEIValidator validator = 
      preparationSchemeURL == null ? new TEIPreparationValidator(): new FromURLValidator(preparationSchemeURL);
    Multiset<String> knownPreparationTitles = HashMultiset.create();
    
    File documentDir = new File(outputDirectory, "PreparationHeader");
    if (!documentDir.exists() && !documentDir.mkdir())
    {
      throw new LaudatioException(messages.getString(
        "COULD NOT CREATE DIRECTORY")
        + documentDir.getAbsolutePath());
    }
    
    Preconditions.checkNotNull(doc.getRootElement()
      .getChild("teiCorpus", null));
    Element preparationRoot = Preconditions.checkNotNull(doc.getRootElement()
      .getChild("teiCorpus", null).getChild("teiCorpus", null));
    
    for(Element preparationHeader : preparationRoot.getChildren("teiHeader", null))
    {
      Preconditions.checkState("PreparationHeader".equals(preparationHeader.getAttributeValue("type")));
      
      // create the subtree for the global corpus header
      Namespace teiNS = Namespace.getNamespace(
        "http://www.tei-c.org/ns/1.0");
      Element tei = new Element("TEI", teiNS);
      tei.addContent(preparationHeader.clone());
      Document newDoc = new Document(tei);
      
      
      if(preparationSchemeURL == null)
      {
        newDoc.addContent(0, new ProcessingInstruction("xml-model", 
          "href=\"" + TEIPreparationValidator.DEFAULT_SCHEME_URL + "\""));
      }
      else
      {
        newDoc.addContent(0, new ProcessingInstruction("xml-model", 
          "href=\"" + preparationSchemeURL + "\""));
      }
      
      // we need to append an empty "text" element after the header
      Element text = new Element("text", teiNS);
      text.setText("");
      tei.addContent(text);
      
      Element fileDesc = Preconditions.checkNotNull(tei.getChild("teiHeader", null).getChild("fileDesc", null));
      
      String outName = UUID.randomUUID().toString();

      Element titleStmt = Preconditions.checkNotNull(fileDesc.getChild("titleStmt", null));
      Element title = Preconditions.checkNotNull(titleStmt.getChild("title", null));
      String corresp = title.getAttributeValue("corresp");
      if(corresp != null)
      {
        if(knownPreparationTitles.contains(corresp))
        {
          knownPreparationTitles.add(corresp);
          outName = corresp +  "_" + knownPreparationTitles.count(corresp);
          log.warn(messages.getString("MORE THAN ONE PREPARATION HEADER"), corresp);
        }
        else
        {
          outName = corresp;
          knownPreparationTitles.add(corresp);
        }
      }
      
      File outputFile = new File(documentDir, outName + ".xml");
      XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
      xmlOut.output(newDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
      log.info(messages.getString("WRITTEN PREPARATION HEADER"), outputFile.getPath());
      
      validator.validate(outputFile);
      
    }
    return validator.getErrors();
  }