private void doStep(Vertex<Text, Text, NullWritable> vertex, Iterable<Text> messages) {
        Text currentComponent = vertex.getValue();
        boolean changed = false;
        // did we get a smaller id ?
        for (Text message : messages) {
            Text candidateComponent = message;
            if (candidateComponent.compareTo(currentComponent) < 0) {
                currentComponent = new Text(candidateComponent); // do clone since candidateComponent is mutable
                changed = true;
            }
        }
        // propagate new component id to the neighbors
        if (changed) {
            vertex.setValue(currentComponent);
            sendMessageToAllEdges(vertex, currentComponent);
        }
    }