Move things around to fix race condition