proper topological ordering