Topological sort implemented