Refactored key generation/regeneration