Split off topological sort module.