refactored db login