refactor applycontroller