State saving to fix race conditions