Move topsort into graph