private Map<String, String> modifyOrder(Random random, Element parent, NodeList nodeList, boolean variables, int mode) {
		Map<String, String> variablesMap = new HashMap<String, String>();
		int[] permutation = buildPermutation(random, nodeList.getLength());
		Element[] elements = new Element[nodeList.getLength()];
		for (int i = 0; i < nodeList.getLength(); i++) {
			Element element = (Element) nodeList.item(i);
			String name = element.getAttribute(InstanceTokens.NAME);
			String canonicalName = null;
			if (variables)
				canonicalName = mode == 2 ? name : InstanceTokens.getVariableNameFor(permutation[i]);
			else
				canonicalName = mode == 1 ? name : InstanceTokens.getConstraintNameFor(permutation[i]);
			// String canonicalName = (variables ? InstanceTokens.getVariableNameFor(permutation[i]) : InstanceTokens.getConstraintNameFor(permutation[i]));
			element.setAttribute(InstanceTokens.NAME, canonicalName);
			variablesMap.put(name, canonicalName);
			if (variables)
				elements[mode == 2 ? i : permutation[i]] = element;
			else
				elements[mode == 1 ? i : permutation[i]] = element;
			//elements[permutation[i]] = element;
		}
		for (int i = 0; i < nodeList.getLength(); i++)
			parent.removeChild(nodeList.item(i));
		for (int i = 0; i < elements.length; i++)
			parent.appendChild(elements[i]);
		return variablesMap;
	}