Extract adding a task into a function.