i think there is place for refactoring .. especially the graph part ... ! i thing it's possbile to create a unique method on the node class