Migrated all code to work effectively inside a Flask app.