fix possible race condition