       print("AVAssetWriter Failed:", "Unknown error")
       stopDisplayLink()
       cleanUp()
+      completionHandler(false)
       return
     }
 
+    completionHandler(true)
+
   }
 
   public func finishWriting(completionHandler: (@escaping (_ url: URL) -> Void)) {
 
     if !isRecording { return }
+
+    if writer.status != .writing { return }
 
     videoInput.markAsFinished()
 


  private func startInputPipeline() -> Bool {

    guard writer.startWriting() else { return false }

    writer.startSession(atSourceTime: kCMTimeZero)


  }

  public func startWriting(completionHandler: (@escaping (_ success: Bool) -> Void) = {_ in }) {

    if isRecording { return }
    isRecording = true
