refactored db access into db/ directory