public Matrix fixDoublingElements(Matrix m, ArrayList<String> W2,
            ArrayList<Set<String>> sortedKeys) {
        Matrix p = new Matrix(m);
        String ids[] = p.getIds();
        int[][] conn = p.getConnections();
        int startPosition = ids.length - W2.size(); //CHECK!
        int[] count = new int[conn[0].length - startPosition];

        for (int i = 0; i < conn.length; i++) {
            for (int j = startPosition; j < conn[0].length; j++) {
                if (conn[i][j] == 1) {
                    count[j - startPosition]++;
                }
            }
        }

        Set<String> fixMe = new TreeSet<>(new NaturalOrderComparator());
        for (int i = 0; i < count.length; i++) {
            if (count[i] >= 2) {
                fixMe.add(W2.get(i));
            }
        }

        ArrayList<String[]> toAdd = new ArrayList<>();
        ArrayList<String[]> toRemove = new ArrayList<>();

        for (String element : fixMe) {
            //Number in the array
            int num = Step10.numberInArrayList(W2, element) + startPosition;
            ArrayList<String> candidates = new ArrayList<>();
            //For keys - find candidates
            for (int i = 0; i < conn.length; i++) {
                if (conn[i][num] == 1) {
                    candidates.add(ids[i]);
                }
            }
            
            Collections.sort(candidates, new findBossKey(sortedKeys));
            //candidates.sort();
            //Connect fixMe ot the first candidate
            p.setValue(candidates.get(0), element, 1);
            //Remove links to all other candidates
            for (int i = 1; i < candidates.size(); i++) {
                p.setValue(candidates.get(i), element, 0);
            }
        }
        return p;
    }