refactored to use Flask-SQLAlchemy extension