Add topological sorting