Refactor code of task and runner