modified method of connecting to DB