modified getAllEdges to getSortedEdges