refactored db usage