Tidy up of S/MIME code and add new functions which will make is easier