db connection refactor