Refactor controller