refactored application_controller code