     
     func getCaptureSession(completion: @escaping (AVCaptureSession?) -> ()) {
         
-        if let captureSession = captureSession {
-            completion(captureSession)
-        
-        } else {
-            
-            let mediaType = AVMediaTypeVideo
-            
-            switch AVCaptureDevice.authorizationStatus(forMediaType: mediaType) {
-                
-            case .authorized:
-                setUpCaptureSession()
-                completion(captureSession)
-                
-            case .notDetermined:
-                AVCaptureDevice.requestAccess(forMediaType: mediaType) { [weak self] granted in
-                    if granted {
-                        self?.setUpCaptureSession()
-                        completion(self?.captureSession)
-                    } else {
-                        completion(nil)
+        func callCompletionOnMainQueue(with session: AVCaptureSession?) {
+            DispatchQueue.main.async {
+                completion(session)
+            }
+        }
+        
+        captureSessionSetupQueue.async { [weak self] in
+            
+            if let captureSession = self?.captureSession {
+                callCompletionOnMainQueue(with: captureSession)
+                
+            } else {
+                
+                let mediaType = AVMediaTypeVideo
+                
+                switch AVCaptureDevice.authorizationStatus(forMediaType: mediaType) {
+                    
+                case .authorized:
+                    self?.setUpCaptureSession()
+                    callCompletionOnMainQueue(with: self?.captureSession)
+                    
+                case .notDetermined:
+                    AVCaptureDevice.requestAccess(forMediaType: mediaType) { granted in
+                        self?.captureSessionSetupQueue.async {
+                            if let captureSession = self?.captureSession {
+                                callCompletionOnMainQueue(with: captureSession)
+                            } else if granted {
+                                self?.setUpCaptureSession()
+                                callCompletionOnMainQueue(with: self?.captureSession)
+                            } else {
+                                callCompletionOnMainQueue(with: nil)
+                            }
+                        }
                     }
-                }
-
-            case .restricted, .denied:
-                completion(nil)
+                    
+                case .restricted, .denied:
+                    callCompletionOnMainQueue(with: nil)
+                }
             }
         }
     }

    
    // MARK: - Private
    
    private func savePhoto(sampleBuffer: CMSampleBuffer?, completion: @escaping (PhotoFromCamera?) -> ()) {
        
        let path = randomTemporaryPhotoFilePath()

    }
    
    private func setUpCaptureSession() {
        
        do {
            #if arch(i386) || arch(x86_64)
                // Preventing crash in simulator
