Further refactoring of DB connection.