Hopefully fixed the race condition