   @IBOutlet weak var allowCameraAccessLabel: UILabel!
   var delegate: AccountCreationDelegate?
   private var session = AVCaptureSession()
+  private let output = AVCaptureMetadataOutput()
   private var layer: AVCaptureVideoPreviewLayer?
-  private var didCapture = false
 
   @IBAction func didPressCancel(sender: UIBarButtonItem) {
+    output.setMetadataObjectsDelegate(nil, queue: nil)
     presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
   }
 

    let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    if let input = try? AVCaptureDeviceInput(device: device) {
      session.addInput(input)
      let output = AVCaptureMetadataOutput()
      session.addOutput(output)
      output.setMetadataObjectsDelegate(self, queue: dispatch_get_main_queue())
      output.metadataObjectTypes = [AVMetadataObjectTypeQRCode]

    captureOutput: AVCaptureOutput!,
    didOutputMetadataObjects metadataObjects: [AnyObject]!,
    fromConnection connection: AVCaptureConnection!) {
      guard metadataObjects.count > 0,
        let metadataObject = metadataObjects.first as? AVMetadataMachineReadableCodeObject
        where metadataObject.type == AVMetadataObjectTypeQRCode,
        let url = NSURL(string: metadataObject.stringValue),
        let account = Account(url: url) else { return }
      output.setMetadataObjectsDelegate(nil, queue: nil)
      presentingViewController?.dismissViewControllerAnimated(true) {
        self.delegate?.createAccount(account)
      }
