fix potential race condition