Fix race condition issues