Export of database to new adjacency list format

Making a pull request since the changes are large but should be grouped together.
This was chopped up into multiple commits so that it might be possible to diff some of the commits and not crash github.