Add a draft of the new main loop, and fix a couple of snags with the DSE topsort