tidied up db connectivity