refactor code of todo controller