Refactor code and create todo to methods