Refactor and test the controller helper