Flask app refactoring

- app-wide objects continue being memorized
- app-wide objects can be accessed through the app object
- tidy up the setup pieces

Merge with care, deployment functionality hasn't been tested (sentry, mail, twitter)