private void combineBlockAgendas() {
    final String filename = "agendas.org";
    long agendaFileNodeID = db.getFileId(filename);
    Cursor cursor = db.getNodeChildren(agendaFileNodeID);

    cursor.moveToFirst();

    String previousBlockTitle = "";
    long previousBlockNode = -1;

    while (cursor.isAfterLast() == false) {
      String name = cursor.getString(cursor.getColumnIndex("name"));

      if (name.indexOf(">") == -1) continue;

      String blockTitle = name.substring(0, name.indexOf(">"));

      if (TextUtils.isEmpty(blockTitle) == false) { // Is a block agenda

        if (blockTitle.equals(previousBlockTitle)
            == false) { // Create new node to contain block agenda
          previousBlockNode =
              db.addNode(agendaFileNodeID, blockTitle, "", "", "", db.getFilenameId(filename));
        }

        String blockEntryName = name.substring(name.indexOf(">") + 1);

        long nodeId = cursor.getLong(cursor.getColumnIndex("_id"));

        Cursor children = db.getNodeChildren(nodeId);
        children.moveToFirst();

        if (blockEntryName.startsWith("Day-agenda") && children.getCount() == 1) {
          blockEntryName = children.getString(children.getColumnIndex("name"));
          children = db.getNodeChildren(children.getLong(children.getColumnIndex("_id")));
          children.moveToFirst();
          cloneChildren(children, previousBlockNode, agendaFileNodeID, blockEntryName, filename);
        } else if (blockEntryName.startsWith("Week-agenda")) {
          while (children.isAfterLast() == false) {
            blockEntryName = children.getString(children.getColumnIndex("name"));
            Cursor children2 = db.getNodeChildren(children.getLong(children.getColumnIndex("_id")));
            children2.moveToFirst();
            cloneChildren(children2, previousBlockNode, agendaFileNodeID, blockEntryName, filename);
            children2.close();
            children.moveToNext();
          }
        } else
          cloneChildren(children, previousBlockNode, agendaFileNodeID, blockEntryName, filename);

        previousBlockTitle = blockTitle;
        db.deleteNode(cursor.getLong(cursor.getColumnIndex("_id")));
        children.close();
      }

      cursor.moveToNext();
    }

    cursor.close();
  }