             context.addLine(to: CGPoint(x: CGFloat(x), y: verticalMiddle + height))
             context.strokePath();
         }
-        let image = UIGraphicsGetImageFromCurrentImageContext()
-        let drawRect = CGRect(x: 0, y: 0, width: (image?.size.width)!, height: (image?.size.height)!)
+        guard let image = UIGraphicsGetImageFromCurrentImageContext() else {
+            NSLog("FDWaveformView failed to get waveform image from context")
+            return
+        }
+        
+        let drawRect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
         context.setFillColor(progressColor.cgColor)
         UIRectFillUsingBlendMode(drawRect, .sourceAtop)
-        let tintedImage = UIGraphicsGetImageFromCurrentImageContext()
+        guard let tintedImage = UIGraphicsGetImageFromCurrentImageContext() else {
+            NSLog("FDWaveformView failed to get tinted image from context")
+            return
+        }
         UIGraphicsEndImageContext()
-        done(image!, tintedImage!)
+        done(image, tintedImage)
     }
 }
 

        reader.add(readerOutput)

        var channelCount = 1
        let formatDesc: [AnyObject] = assetTrack.formatDescriptions as [AnyObject]
        for item in formatDesc {
            let fmtDesc = CMAudioFormatDescriptionGetStreamBasicDescription(item as! CMAudioFormatDescription)
            guard fmtDesc != nil else { return }
            channelCount = Int((fmtDesc?.pointee.mChannelsPerFrame)!)
        }

        var sampleMax = noiseFloor


    // TODO: switch to a synchronous function that paints onto a given context? (for issue #2)
    func plotLogGraph(_ samples: [CGFloat], maximumValue max: CGFloat, zeroValue min: CGFloat, imageHeight: CGFloat, done: (_ image: UIImage, _ selectedImage: UIImage)->Void) {
        guard let context = UIGraphicsGetCurrentContext() else {
            NSLog("FDWaveformView failed to get graphics context")
            return
        }
        
        let imageSize = CGSize(width: CGFloat(samples.count), height: imageHeight)
        UIGraphicsBeginImageContext(imageSize)
        context.setShouldAntialias(false)
        context.setAlpha(1.0)
        context.setLineWidth(1.0)
