refactored db connection