Fix possible concurrency errors