rearranging database connection code again