             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 failBlock = self._failureBlock{
-                    failBlock(error)
-                }
-                else{
-                    self.delegate!.websocketDidDisconnect(error)
-                }
+                if let disconnect = self.disconnectedBlock {
+                    disconnect(error)
+                }
+                self.delegate?.websocketDidDisconnect(error)
                 writeError(errCode)
                     
                 return

                    dispatch_async(dispatch_get_main_queue(),{
                        //self.workaroundMethod()
                        let error = self.errorWithDetail("Invalid HTTP upgrade", code: 1)
                        if let failBlock = self._failureBlock{
                            failBlock(error)
                        }
                        else{
                            self.delegate!.websocketDidDisconnect(error)
                        }
                    })
                }
            } else {

        isRunLoop = false
        connected = false
        dispatch_async(dispatch_get_main_queue(),{
            if let disconnectBlock = self.disconnectedBlock {
                disconnectBlock(error)
            }
            self.delegate?.websocketDidDisconnect(error)
        })
    }
    
