private static int[][] removeDeletedCell(final int[][] groupIndices, final int deletedIndex) {
    for(int i=0; i<groupIndices.length; i++) {
      for(int j=0; j<groupIndices [i].length; j++) {
        if (groupIndices [i][j] == deletedIndex) {
          int[][] newIndices;
          if (groupIndices [i].length <= 2) {
            // deleted cell is contained in a group with 1 or 2 cells => delete entire group
            newIndices = new int[groupIndices.length-1][];
            for (int newI = 0; newI < i; newI++) {
              newIndices [newI] = groupIndices [newI].clone();
            }
            for(int newI=i+1; newI<groupIndices.length; newI++) {
              newIndices [newI-1] = groupIndices [newI].clone();
            }
          }
          else {
            // deleted cell is contained in a group with more than 2 cells => keep the group and delete only the item
            newIndices = new int[groupIndices.length][];
            for(int newI=0; newI<groupIndices.length; newI++) {
              if (newI == i) {
                newIndices [newI] = new int[groupIndices [newI].length-1];
                System.arraycopy(groupIndices [newI], 0, newIndices [newI], 0, j);
                System.arraycopy(groupIndices [newI], j+1, newIndices [newI], j, groupIndices [i].length-j-1);
              }
              else {
                newIndices [newI] = new int[groupIndices [newI].length];
                System.arraycopy(groupIndices [newI], 0, newIndices [newI], 0, groupIndices [i].length);
              }
            }
          }
          return newIndices;
        }
      }
    }
    return groupIndices;
  }
private static int[][] removeDeletedCell(final int[][] groupIndices, final int deletedIndex)