extrat adding a task into a function