cleanup test function
Additional debug output
Fix plaintext encoding of messages