refactored db interaction