Added topological sort