 			
 			self.webUILoaded = true
 			
-			if let name = UserDefaults.standard.string(forKey: self.curDocNameKey) {
+			if let name = UserDefaults.standard.string(forKey: self.curDocNameKey) ?? UserDefaults.standard.string(forKey: self.lastDocNameKey) {
 				//let _ = self.openProgram(byName: name)
                 if FrontendCallbackCenter.shared.setFilePreference(name) {
                     NSLog("Successfully set the filename to \(name)")

	//MARK: Document Handling
	static let curDocNeedsNameKey = "CurrentDocumentNeedsName"
	static let curDocNameKey = "CurrentDocumentName"
	let curDocNeedsNameKey = "CurrentDocumentNeedsName"
	let curDocNameKey = "CurrentDocumentName"
	
	private var realDoc = BBXDocument(fileURL: URL(
		fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory,

	
	private func closeCurrentProgram(completion: ((Bool) -> Void)? = nil) {
		self.document.close(completionHandler: { suc in
            let curDocName = DataModel.shared.getSetting(self.curDocNameKey)
            UserDefaults.standard.set(curDocName, forKey: self.lastDocNameKey)
			UserDefaults.standard.set(nil, forKey: self.curDocNameKey)
			if let completion = completion {
				completion(suc)
