final cleanup for PEM serialization

final cleanup originally started by #1564