Refactored views and tasks to use SQlAlchemy.