tidy up of encryption and reply code
split out encryption and logging