fixing a race condition