add topological sorting