Moved database stuff into its own module