Added sorting to nodes prior to ordering
Sorting nodes in the graph prior to ordering so that the ordering of unrelated nodes is deterministic.