fixes race condition