             return
         }
         
-        sliceAsset(withRange: sampleRange, andDownsampleTo: Int(imageSize.width)) {
-            (samples, sampleMax) in
-            self.plotLogGraph(samples, maximumValue: sampleMax, zeroValue: self.noiseFloor, imageHeight: self.imageSize.height) {
-                (image) in
-                finish(with: image)
-            }
-        }
+        let image: UIImage? = {
+            guard
+                let (samples, sampleMax) = sliceAsset(withRange: sampleRange, andDownsampleTo: Int(imageSize.width)),
+                let image = plotLogGraph(samples, maximumValue: sampleMax, zeroValue: self.noiseFloor, imageHeight: self.imageSize.height)
+            else { return nil }
+            
+            return image
+        }()
+        
+        finish(with: image)
     }
 
     /// Read the asset and create create a lower resolution set of samples
-    func sliceAsset(withRange slice: CountableRange<Int>, andDownsampleTo targetSamples: Int, done: (_ samples: [CGFloat], _ sampleMax: CGFloat) -> Void) {
+    func sliceAsset(withRange slice: CountableRange<Int>, andDownsampleTo targetSamples: Int) -> (samples: [CGFloat], sampleMax: CGFloat)? {
         guard
             !slice.isEmpty,
             let reader = try? AVAssetReader(asset: audioContext.asset)
-            else {
-                finish(with: nil)
-                return
-        }
+            else { return nil }
         
         reader.timeRange = CMTimeRange(start: CMTime(value: Int64(slice.lowerBound), timescale: audioContext.asset.duration.timescale),
                                        duration: CMTime(value: Int64(slice.count), timescale: audioContext.asset.duration.timescale))

//            return
//        }
//        UIGraphicsEndImageContext()
        done(image)
    }
}


        // if (reader.status == AVAssetReaderStatusFailed || reader.status == AVAssetReaderStatusUnknown)
        // Something went wrong. Handle it.
        if reader.status == .completed {
            return (outputSamples, sampleMax)
        } else {
            print(reader.status)
            return nil
        }
    }
    
