Refactor concurrency code