pull DB write out of routes.py, first pass