make token persistence atomic