protected boolean orderConnections(NeuralNetwork neuralNetwork, Layer currentLayer, Set<Layer> calculatedLayers, Set<Layer> inProgressLayers, List<ConnectionCandidate> calculateCandidates) {
	boolean result = false;

	if (calculatedLayers.contains(currentLayer) || Util.isBias(currentLayer)) {
	    result = true;
	} else if (!inProgressLayers.contains(currentLayer)) {
	    inProgressLayers.add(currentLayer);
	    List<ConnectionCandidate> currentCandidates = new ArrayList<ConnectionCandidate>();

	    boolean hasNoBiasConnections = false;
	    for (Connections c : currentLayer.getConnections(neuralNetwork)) {
		Layer opposite = Util.getOppositeLayer(c, currentLayer);
		if (orderConnections(neuralNetwork, opposite, calculatedLayers, inProgressLayers, calculateCandidates)) {
		    currentCandidates.add(new ConnectionCandidate(c, currentLayer));

		    if (!Util.isBias(opposite)) {
			hasNoBiasConnections = true;
		    }
		}
	    }

	    if (currentCandidates.size() > 0 && hasNoBiasConnections)  {
		calculateCandidates.addAll(currentCandidates);
		result = true;
	    }

	    inProgressLayers.remove(currentLayer);
	    calculatedLayers.add(currentLayer);
	}

	return result;
    }