Fix race condition