controller code refactor