Added topological sort.