Trying to fix a race condition