Creating and updating the controller function