Code refactor on the controller