public static void saveModel(LibraryModel lmodel)
  {
    try
    {      
      JsonModel jmodel = new JsonModel();
      jmodel.info = lmodel.info;
      
      List<ArrayList<JsonPiece>> pieces = new ArrayList<ArrayList<JsonPiece>>();
      ArrayList<JsonPiece> current = null;
      for (Level l : lmodel.model)
      {
        current = new ArrayList<JsonPiece>();
        pieces.add(current);
        for (Piece piece : l)
        {
          if (piece.type != PieceType.CAP)
          {
            JsonPiece jpiece = new JsonPiece();
            jpiece.type = PieceType.forPiece(piece.type);
            jpiece.color = PieceColor.forColor(piece.color);
            jpiece.x = piece.x;
            jpiece.y = piece.y;
            current.add(jpiece);
          }
        }
      }
      
      jmodel.pieces = new JsonPiece[pieces.size()][];
      for (int i = 0; i < pieces.size(); ++i)
      {
        jmodel.pieces[i] = new JsonPiece[pieces.get(i).size()];
        pieces.get(i).toArray(jmodel.pieces[i]);
      }
      
      FileUtils.writeJson(lmodel.file, JsonModel.class, jmodel, true);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }