Added: now process undirected edges (not tested)