makes topological sort work