     
     // published messages
     open var messages: [UInt16: CocoaMQTTMessage] = [:]
-    // subscribed topics
-    open var subscriptions: [UInt16: String] = [:]
+    
+    // subscribed topics. (dictionary structure -> [msgid: [topicString: QoS]])
+    open var subscriptions: [UInt16: [String: CocoaMQTTQOS]] = [:]
+    var subscriptionsWaitingAck: [UInt16: [String: CocoaMQTTQOS]] = [:]
+    var unsubscriptionsWaitingAck: [UInt16: [String: CocoaMQTTQOS]] = [:]
 
     // global message id
     var gmid: UInt16 = 1

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

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


        let msgid = nextMessageID()
        let frame = CocoaMQTTFrameSubscribe(msgid: msgid, topic: topic, reqos: qos.rawValue)
        send(frame, tag: Int(msgid))
        subscriptionsWaitingAck[msgid] = [topic:qos]
        return msgid
    }

