refactored db functions
Merged Drew and Chris