refactored db stuff