Refactoring for Flask-Login