         #if DEBUG
             NSLog("CocoaMQTT: SUBACK Received: \(msgid)")
         #endif
-
-        if let topic = subscriptions.removeValue(forKey: msgid) {
+        
+        if let topicDict = subscriptionsWaitingAck.removeValue(forKey: msgid) {
+            let topic = topicDict.first!.key
+            subscriptions[msgid] = topicDict
             delegate?.mqtt(self, didSubscribeTopic: topic)
+        } else {
+            #if DEBUG
+                NSLog("CocoaMQTT: UNEXPECT SUBACK Received: \(msgid)")
+            #endif
         }
     }
 

        #if DEBUG
            NSLog("CocoaMQTT: UNSUBACK Received: \(msgid)")
        #endif

        if let topic = subscriptions.removeValue(forKey: msgid) {
            delegate?.mqtt(self, didUnsubscribeTopic: topic)
        }
    }


    open func unsubscribe(_ topic: String) -> UInt16 {
        let msgid = nextMessageID()
        let frame = CocoaMQTTFrameUnsubscribe(msgid: msgid, topic: topic)
        unsubscriptionsWaitingAck[msgid] = [topic:CocoaMQTTQOS.qos0]
        send(frame, tag: Int(msgid))
        return msgid
    }
