Restructured Flask app for better separation of concerns, fixes #3