fix a race condition