Fix potential concurrency issues