cleaned up topsort