cleanup references to leveldb
stabilize topological sort

This ensures that on different systems we get the same id ordering. The
specific problem was the use of a set keyed by pointer, which could change even
depending on the memory structure available to the application. This leads to
unstable behavior and (thankfully) failing tests that indicated the problem.