Trying to fix race condition