Refactored certificate generation code.