Modified to use sqlalchemy objects