factored out databse connection