diff --git a/pd/nw/dialog_prefs.html b/pd/nw/dialog_prefs.html
index ba491c778c50a710c0a9cb94dd74cf9c52ec96de..04bfb54a98a23a3cd6639f4e01ce15e7f19094f0 100644
--- a/pd/nw/dialog_prefs.html
+++ b/pd/nw/dialog_prefs.html
@@ -393,6 +393,12 @@ function apply() {
 function cancel() {
     var i, attrs, gfxstub;
     pdgui.post("closing the window at this point");
+    // There seems to be a bug in nwjs 0.13 beta3 that doesn't call the
+    // "close" event below. This has the symptom of making it impossible
+    // to click the "Ok" button and open the preferences dialog again after
+    // that. To see if the bug is gone, try removing the next line and see
+    // if you can open the Prefs dialog after clicking "Ok".
+    pdgui.remove_dialogwin(pd_object_callback);
     window.close(true);
     //pdgui.pdsend(pd_object_callback, "cancel");
 }
diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js
index b038c9d0500a8428d4d8302388ae735826ed540a..6f38388e22eb42e39424b815369d9afb4da1de30 100644
--- a/pd/nw/pd_canvas.js
+++ b/pd/nw/pd_canvas.js
@@ -615,8 +615,7 @@ var canvas_events = (function() {
     document.querySelector("#canvas_find_button").addEventListener("click",
         events.find_click);
     // We need to separate these into nw_window events and html5 DOM events
-    // closing the Window
-    // this isn't actually closing the window yet
+    // closing the Window this isn't actually closing the window yet
     gui.Window.get().on("close", function() {
         pdgui.pdsend(name, "menuclose 0");
     });
diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index d4d39b20037d5f08fd25c6f0bb4168c76d2e6a51..e76076e89f420fd9f48c4890d92e2fc537b9098e 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -3312,8 +3312,7 @@ function gui_pd_dsp(state) {
 
 function open_prefs() {
     if (!dialogwin["prefs"]) {
-        dialogwin["prefs"] = nw_create_window("prefs", "prefs",
-            265, 540, 20, 20, null);
+        nw_create_window("prefs", "prefs", 265, 540, 20, 20, null);
     }
 }