             keepalive.lowByte                   // VARIA BYTE 10  Keep Alive LSB
         ]
 
-        var messageBytes = headerBytes + encodeUTF8Length(client) + [UInt8](client.utf8)
+        var messageBytes = headerBytes + encode(string: client)
 
         if let username = username {
-            messageBytes += (encodeUTF8Length(username) + [UInt8](username.utf8))
+            messageBytes += encode(string: username)
         }
 
         if let password = password {
-            messageBytes += (encodeUTF8Length(password) + [UInt8](password.utf8))
+            messageBytes += encode(string: password)
         }
 
         outputStream?.write(messageBytes, maxLength: messageBytes.count)

        return remainingBytes
    }
    
    private func encodeUTF8Length(_ string: String) -> [UInt8] {
        return [UInt16(string.utf8.count).highByte, UInt16(string.utf8.count).lowByte]
    }
    
}

        // TODO: Add 2 (for messageId) if/when QOS > 0
        let remainingLengthBytes = encodeVariableLength(2 + topic.utf8.count + message.count)

        let headerBytes: [UInt8] = [
            	0x30] +                         // FIXED BYTE 1   3 = PUBLISH, 0 = DUP QoS RETAIN
            remainingLengthBytes                // remaining length, variable

        let messageBytes = headerBytes + encode(string: topic) + [UInt8](message)
        outputStream?.write(messageBytes, maxLength: messageBytes.count)
    }

