Adding code for topological sort etc