Handle 541 responses

Fixes #125
Commit missing bits from an earlier commit
Merge branch 'master' into tls_support