refactor submitTasks function