       when OpfFile::mediaType
         # add the opf to the copy of the Epubcontainer
         # that is in allContent
-        allContent
-          .findWhere({mediaType: EpubContainer::mediaType})
-          .addChild(model)
+        epubContainer.addChild(model)
       else
         allContent.each (book) ->
           book.manifest?.add(model) # Only books have a manifest

      else
        # Save all the models that have changes
        changedModels = @filter (model) -> model.isDirty()

      writeFiles(changedModels)


        changedModels = @filter (model) ->
          if contextModel && model != contextModel
            switch model.mediaType
              # sometimes there is an epubContainer in allContent, this is bad - ignore it
              when EpubContainer::mediaType then return false
              when OpfFile::mediaType then return model.isDirty() # Always add OPF files
              when XhtmlFile::mediaType
                return includeNewContent and model.isNew()
