     }
 
     let packetListSize = MemoryLayout.offset(of: \MIDIPacketList.packet.data)! + bufferSize
-    let rawPacketListPtr = UnsafeMutableRawPointer.allocate(byteCount: packetListSize, alignment: MemoryLayout<MIDIPacketList>.alignment)
-    let packetListPtr = rawPacketListPtr.initializeMemory(as: MIDIPacketList.self, repeating: MIDIPacketList(), count: 1)
+    var packetListData = Data(count: packetListSize)
 
     let queue = DispatchQueue(label: "com.snoize.SnoizeMIDI.CustomMIDISendSysex")
     queue.setTarget(queue: DispatchQueue.global(priority: .high))
 
     func sendNextBuffer() {
-        let packetBytes = min(Int(request.pointee.bytesToSend), bufferSize)
-
-        let curPacket = MIDIPacketListInit(packetListPtr)
-        _ = MIDIPacketListAdd(packetListPtr, packetListSize, curPacket, 0, packetBytes, request.pointee.data)
-
-        MIDISend(port, request.pointee.destination, packetListPtr)
-
-        request.pointee.data += packetBytes
-        request.pointee.bytesToSend -= UInt32(packetBytes)
+        let packetDataSize = min(Int(request.pointee.bytesToSend), bufferSize)
+
+        packetListData.withUnsafeMutableBytes { (packetListRawBufferPtr: UnsafeMutableRawBufferPointer) in
+            let packetListPtr = packetListRawBufferPtr.bindMemory(to: MIDIPacketList.self).baseAddress!
+
+            let curPacket = MIDIPacketListInit(packetListPtr)
+            _ = MIDIPacketListAdd(packetListPtr, packetListSize, curPacket, 0, packetDataSize, request.pointee.data)
+
+            MIDISend(port, request.pointee.destination, packetListPtr)
+        }
+
+        request.pointee.data += packetDataSize
+        request.pointee.bytesToSend -= UInt32(packetDataSize)
         if request.pointee.bytesToSend == 0 {
             request.pointee.complete = true
         }


}

private func customMIDISendSysex(_ request: UnsafeMutablePointer<MIDISysexSendRequest>, _ bufferSize: Int, _ perBufferDelay: Double) -> OSStatus {
    guard let client = SMClient.sharedClient,
          bufferSize >= 3 && bufferSize <= 32767 else { return OSStatus(paramErr) }

        }
        else {
            request.pointee.completionProc(request)
            MIDIPortDispose(port)
        }
    }

