 
     /// Removes the `alertController` from memory.
     func cleanUp() {
+        guard let updaterWindow = updaterWindow else { return }
         alertController?.hide(window: updaterWindow)
         alertController?.dismiss(animated: true, completion: nil)
         updaterWindow.resignKey()

        // If the alertType is .none, an alert will not be presented.
        // If the `updaterWindow` is not hidden, then an alert is already presented.
        // The latter prevents `UIAlertController`'s from appearing on top of each other.
        if rules.alertType != .none, updaterWindow.isHidden {
            alertController?.show(window: updaterWindow)
        } else {
            // This is a safety precaution to avoid multiple windows from presenting on top of each other.

        window.rootViewController = viewController
        return window
    }

    @available(iOS 13.0, *)
    private func getFirstForegroundScene() -> UIWindowScene? {
        let connectedScenes = UIApplication.shared.connectedScenes
        if let windowActiveScene = connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
            return windowActiveScene
        } else {
            return connectedScenes.first(where: { $0.activationState == .foregroundInactive }) as? UIWindowScene
        }
    }
}
