Factoring out database code into its own file