Refactor Controller to remove duplicate code