     }
     
 //    cleanup2:
-    free(transferBuffer)
-    free(swapBuffer)
-    AudioFileClose(forwardAudioFile!)
-    AudioFileClose(backwardAudioFile!)
-
+    cleanup2(transferBuffer: transferBuffer, swapBuffer: swapBuffer, forwardAudioFile: forwardAudioFile, backwardAudioFile: backwardAudioFile)
     
     return err
 }
+
+fileprivate func cleanup1(outputBuffer: UnsafeMutableRawPointer?, sourceExtAudioFile: ExtAudioFileRef?, forwardAudioFile: AudioFileID?) {
+    if let outputBuffer = outputBuffer { free(outputBuffer) }
+    if let sourceExtAudioFile = sourceExtAudioFile { ExtAudioFileDispose(sourceExtAudioFile) }
+    if let forwardAudioFile = forwardAudioFile { AudioFileClose(forwardAudioFile) }
+}
+
+fileprivate func cleanup2(transferBuffer: UnsafeMutableRawPointer?, swapBuffer: UnsafeMutableRawPointer?,
+                          forwardAudioFile: AudioFileID?, backwardAudioFile: AudioFileID?) {
+    
+    if let transferBuffer = transferBuffer { free(transferBuffer) }
+    if let swapBuffer = swapBuffer { free(swapBuffer) }
+    if let forwardAudioFile = forwardAudioFile { AudioFileClose(forwardAudioFile) }
+    if let backwardAudioFile = backwardAudioFile { AudioFileClose(backwardAudioFile) }
+}

        err = ExtAudioFileRead(sourceExtAudioFile!,
                               &packetsPerBuffer,
                               &convertedData)
//        IF_ERR_GOTO_CLEANUP_1

        if (frameCount == 0) {
            print("done reading file")

                                 &format,
                                 AudioFileFlags.eraseFile, // notice: have an enum for this (but not for flags in the ASBD)
                                 &forwardAudioFile)
    if err != noErr { return err }

    // convert to a flat file
    // kind of borrowed from my Core Audio book
