Refactors and generates key/cert