Fix NREPL-53 by rewriting the topological sort