         }
     }
 
-    func close(directly: Bool = true) {
-        searchController.dismiss(animated: true) { [unowned self] in
-            if !directly {
-                if self.navigationController?.viewControllers[0] === self {
-                    self.dismiss(animated: true) {
-                        self.onDismissCallback?(self)
-                    }
-                }
-                else {
-                    self.onDismissCallback?(self)
-                    self.navigationController?.popViewController(animated: true)
-                }
-            }
-            else {
+    func close() {
+        if searchController.isFirstResponder {
+            searchController.dismiss(animated: true) { [unowned self] in
                 self.onDismissCallback?(self)
             }
+        }
+        
+        if self.navigationController?.viewControllers[0] === self {
+            self.dismiss(animated: true) { [unowned self] in
+                self.onDismissCallback?(self)
+            }
+        }
+        else {
+            self.onDismissCallback?(self)
+            self.navigationController?.popViewController(animated: true)
         }
     }
 }

            }
        }

        close(directly: false)
    }
    
    @objc private func keyboardWillShow(_ notification: Notification) {

    }

    private func setInitialValue() {
        if let initialValue = edit, initialValue.trimmingCharacters(in: whitespace).characters.count > 0 {
            if !forceNormalization {
                hideForceNormalizationCell = true
            }
            
            searchController.searchBar.textField?.text = initialValue.replacingOccurrences(of: addressSufix, with: "")
