Fixed potential concurrency issues