Code cleanup
Fixed possible failure on TLS renegotiation in write step