Add topological sort