added topological traversal for DAG