Include topological sort mechanism. Remove some debug logging.