Database refactor

Break out the database to its own file and refactor it so that it does not
use so many hardcoded values