close rw if error on handshake
refactor hash calculation