adding topological sort