refactor main controller