Rework database connection code.