better functs
topological sort working