Moved the database code into its own file.
Merge branch 'separate_db'