refactor session usage as suggested by sqlalchemy's docs