Refactored code in authorize_controller.