correcting direction of edges