Set task_id as a global and update it based on the task list length