         ]
         
         for encoding in encodingsToTry {
-            if let string = String(data: payload, encoding: encoding) {
+            if let payload = payload,
+                let string = String(data: payload, encoding: encoding) {
                 return string
             }
         }

            let message = rawMessage.pointee
            // If there are issues with topic string, drop message on the floor
            let topic = String(cString: message.topic)
            let payload = Data(bytes: message.payload, count: Int(message.payloadlen))
            let mqttMessage = MQTTMessage(messageId: Int(message.mid), topic: topic, payload: payload, qos: message.qos, retain: message.retain)
            callback(mqttMessage)
        }

public struct MQTTMessage {
    public let messageId: Int
    public let topic: String
    public let payload: Data?
    public let qos: Int32
    public let retain: Bool
    
    public init(messageId: Int, topic: String, payload: Data?, qos: Int32, retain: Bool) {
        self.messageId = messageId
        self.topic = topic
        self.payload = payload
