Refactor to access db via orm.