Improvements

I have made several fixes and improvements (from my point of view :-)) ...
what about creating a method for checking certificate type, because the code is duplicated multiple times?