reorganized trace_edges code.