Fixing a race condition