Avoid 'can't add to hash while iterating' error