More refactoring
Refactored certificate handling