     private var fragBuffer: NSData?
     public var headers = Dictionary<String,String>()
     public var voipEnabled = false
-    private var _connectedBlock: (() -> ())? = nil
-    private var _disconnectedBlock: (() -> ())? = nil
-    private var _failureBlock: ((NSError) -> ())? = nil
-    private var _receivedTextBlock: ((String) -> ())? = nil
-    private var _receivedDataBlock: ((NSData) -> ())? = nil
+    private var connectedBlock: ((Void) -> Void)? = nil
+    private var disconnectedBlock: ((NSError?) -> Void)? = nil
+    private var receivedTextBlock: ((String) -> Void)? = nil
+    private var receivedDataBlock: ((NSData) -> Void)? = nil
     public var isConnected :Bool {
         return connected
     }

    public init(url: NSURL) {
        self.url = url
    }

    public convenience init(url: NSURL, protocols: Array<String>) {
        self.init(url: url)
        optionalProtocols = protocols
    }
    
    public convenience init(url: NSURL, connect:() -> (), disconnect:() -> (), failure:(error:NSError) -> (), text:(textReceived: String) -> (), data:(dataReceived: NSData) -> ()) {
        self.init(url: url)
        _connectedBlock = connect
        _disconnectedBlock = disconnect
        _failureBlock = failure
        _receivedTextBlock = text
        _receivedDataBlock = data
    }
    
    public convenience init(url: NSURL, connect:() -> (), disconnect:() -> (), failure:(error:NSError) -> (), text:(textReceived: String) -> ()) {
        self.init(url: url)
        _connectedBlock = connect
        _disconnectedBlock = disconnect
        _failureBlock = failure
        _receivedTextBlock = text
    }
    
    public convenience init(url: NSURL, connect:() -> (), disconnect:() -> (), failure:(error:NSError) -> (), data:(dataReceived: NSData) -> ()) {
        self.init(url: url)
        _connectedBlock = connect
        _disconnectedBlock = disconnect
        _failureBlock = failure
        _receivedDataBlock = data
    }
    
    public convenience init(url: NSURL, connect:() -> (), disconnect:() -> (), text:(textReceived: String) -> ()) {
        self.init(url: url)
        _connectedBlock = connect
        _disconnectedBlock = disconnect
        _receivedTextBlock = text
    }
    
    public convenience init(url: NSURL, connect:() -> (), disconnect:() -> (), data:(dataReceived: NSData) -> ()) {
        self.init(url: url)
        _connectedBlock = connect
        _disconnectedBlock = disconnect
        _receivedDataBlock = data
    }

    ///Connect to the websocket server on a background thread

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