                     let errCode = CloseCode.ProtocolError.rawValue
                     let error = self.errorWithDetail("second and beyond of fragment message must be a continue frame",
                         code: errCode)
-                    if let disconnect = self.disconnectedBlock {
-                        disconnect(error)
-                    }
-                    self.delegate?.websocketDidDisconnect(self, error: error)
+                    self.doDisconnect(error)
                     writeError(errCode)
                     return
                 }

            if((isMasked > 0 || (RSVMask & buffer[0]) > 0) && receivedOpcode != OpCode.Pong.rawValue) {
                let errCode = CloseCode.ProtocolError.rawValue
                let error = self.errorWithDetail("masked and rsv data is not currently supported", code: errCode)
                if let disconnect = self.disconnectedBlock {
                    disconnect(error)
                }
                self.delegate?.websocketDidDisconnect(self, error: error)
                writeError(errCode)
                return
            }

        outputStream = nil
        isRunLoop = false
        connected = false
        self.doDisconnect(error)
    }
    
    ///handles the incoming bytes and sending them to the proper processing method
