refactorized topological_sort example