             "channel": channels
         ]
         
-        RestApiManager.sharedInstance.makeHTTPGetRequest(path: baseURL, parameters: params, user: user, password : self.secretKey, onCompletion: { json, err in
+        RestApiManager.sharedInstance.makeHTTPGetRequest(path: baseURL, parameters: params, user: user, password : self.secretKey, onCompletion: { [weak self] json, err in
             do {
                 
                 let messages = try JsonConverter.sharedInstance.handleMessageEvent(json: json);
                 
                 for m in messages {
                     
-                    if let chixs = self.init_indexes[m.topic()] {
+                    if let chixs = self?.init_indexes[m.topic()] {
                         if let ixs = chixs[m.channel()] {
                             if m.index() > ixs {
                                 listener(m, nil)
-                                self.init_indexes[m.topic()]?[m.channel()] = m.index()
+                                self?.init_indexes[m.topic()]?[m.channel()] = m.index()
                             }
                         } else {
                             listener(m, nil)
-                            self.init_indexes[m.topic()]?[m.channel()] = m.index()                                }
+                            self?.init_indexes[m.topic()]?[m.channel()] = m.index()                                }
                     } else {
                         listener(m, nil)
-                        self.init_indexes[m.topic()] = [ : ]
-                        self.init_indexes[m.topic()]?[m.channel()] = m.index()
+                        self?.init_indexes[m.topic()] = [ : ]
+                        self?.init_indexes[m.topic()]?[m.channel()] = m.index()
                     }
                 }
                 callback();

        mqtt?.lastWillMessage = MQTTPubMsg(topic: "presence/" + self.pubKey + "/" + token, payload: Data(bytes: [0]), retain: true, QoS: MQTTQoS.atLeastOnce);
        mqtt?.delegate = mqtt;
        
        mqtt?.addMessageListener({ ref, message in
            self.handleMqttMessage(m: message);
        });
        
        mqtt?.connect(completion: { mqtt_connected, error in
            if (mqtt_connected) {
                self.mqtt?.subscribe(to: "exceptions", delivering: .atLeastOnce, completion: nil)
                self.mqtt?.publish(Data([1]), in: "presence/" + self.pubKey + "/" + token, delivering: .atLeastOnce, retain: true, completion: nil)
                self.active = true
                connected!(self.active, self);
            }
        }, disconnect: { session in
            if (self.active) {
                print("Connection dropped -> reconnection in 5 sec.")                
                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5)) {
                    session.connect(completion: { mqtt_connected, error in
                        if (mqtt_connected) {
                            self.mqtt?.subscribe(to: "exceptions", delivering: .atLeastOnce, completion: nil)
                            self.mqtt?.publish(Data([1]), in: "presence/" + self.pubKey + "/" + token, delivering: .atLeastOnce, retain: true, completion: nil)
                            self.active = true
                            connected!(self.active, self);
                        }
                    });
                }
            }            
        }, socketerr: { session in
            if (self.active) {
                print("Socket error")
            }
        })
    }
    
    private func connectionPoints(callback : @escaping (_ token : String, _ settings : [ String : [[String : String]] ]) -> Void) {

                } else {
                    
                    if ch != -1 {
                        self.read(topic, group: group, channels: [ch], listener: listener, callback: { [weak self] in
                            self?.mqtt?.subscribe(topic, channel: ch, group: group, qos: .atLeastOnce, callback : { meta, err in
                                callback?(meta, err)
                            })
                        });
