refactor code of controllers