Refactored the controller class