Refactors before sqlalchemy