refractor code in controller to take away logic