Remove duplicate code from certificate_generator