Fix concurrency issues by scheduling in a task