Created the logic for the controller