move db functions into db.py