fix topological sort