Make it work when run multiple times in the same process

Copy the hash of formats to a function-local var before deleting it's
keys