diff --git a/src/g_canvas.c b/src/g_canvas.c
index 797d1a0e4e8e5e89b9822406c11e6c421e55647d..66591eb26e9b7794bd9e3361b39d0121e907e18c 100644
--- a/src/g_canvas.c
+++ b/src/g_canvas.c
@@ -351,6 +351,11 @@ void linetraverser_skipobject(t_linetraverser *t)
 /* -------------------- the canvas object -------------------------- */
 int glist_valid = 10000;
 
+//static void canvas_manual_pd_free(t_canvas *x) {
+//	sys_flushtogui();
+//	pd_free(&x->gl_pd);
+//}
+
 void glist_init(t_glist *x)
 {
         /* zero out everyone except "pd" field */
@@ -377,6 +382,12 @@ t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv)
     // jsarlo
     x->gl_magic_glass = magicGlass_new((int)x);
     // end jsarlo
+
+	//if we are root canvas set the clock for script based destructor of the window
+	//if (!owner) {
+	//	x->gl_destroy = clock_new(x, (t_method)canvas_manual_pd_free);
+	//}
+
     x->gl_obj.te_type = T_OBJECT;
     if (!owner)
         canvas_addtolist(x);
@@ -808,6 +819,10 @@ void canvas_free(t_canvas *x)
     if (x->gl_magic_glass)
       magicGlass_free(x->gl_magic_glass);
     // end jsarlo
+
+	//delete clock for gl_destroy
+	//if (x->gl_destroy) clock_free(x->gl_destroy);
+
     canvas_noundo(x);
     if (canvas_editing == x)
         canvas_editing = 0;
diff --git a/src/g_canvas.h b/src/g_canvas.h
index 2501ebbd690dac9e3873f0caa9f7aeac526fab43..be574f24900b19252ade5b33d5edd567e7c2aba4 100644
--- a/src/g_canvas.h
+++ b/src/g_canvas.h
@@ -193,6 +193,7 @@ struct _glist
     // jsarlo
     t_magicGlass *gl_magic_glass;   /* magic glass object */
     // end jsarlo
+	//t_clock  *gl_destroy;			/* for script-based closing of the patch */
 };
 
 #define gl_gobj gl_obj.te_g
diff --git a/src/g_editor.c b/src/g_editor.c
index 40393b8d333725b9399620c50bad9ef22c73a331..e73bfbe9701e016453bd8714e8ca399328c92dca 100644
--- a/src/g_editor.c
+++ b/src/g_editor.c
@@ -2735,17 +2735,13 @@ void glob_verifyquit(void *dummy, t_floatarg f)
     else glob_quit(0);
 }
 
+void canvas_dofree(t_gobj *dummy, t_glist *x)
+{
+	pd_free(&x->gl_pd);
+}
+
     /* close a window (or possibly quit Pd), checking for dirty flags.
     The "force" parameter is interpreted as follows:
-
-		FOR INTERNAL USE (using it explicitly via pd messages induces
-		a crash because pd_free is called before the previous function
-		has run its course and thus you end up with hard-to-trace crash)
-	   -1 - request from GUI to close, no verification
-			(after it returns back from tcl/tk side of things to avoid
-			freeing before the last method has run its course)
-
-		OFFICIAL USE
         0 - request from GUI to close, verifying whether clean or dirty
         1 - request from GUI to close, no verification
         2 - verified - mark this one clean, then continue as in 1
@@ -2755,9 +2751,7 @@ void canvas_menuclose(t_canvas *x, t_floatarg fforce)
 {
     int force = fforce;
     t_glist *g;
-	if (force == -1)
-		pd_free(&x->gl_pd);
-    else if (x->gl_owner && (force == 0 || force == 1))
+	if (x->gl_owner && (force == 0 || force == 1))
         canvas_vis(x, 0);   /* if subpatch, just invis it */
     else if (force == 0)    
     {
@@ -2790,12 +2784,17 @@ void canvas_menuclose(t_canvas *x, t_floatarg fforce)
                 canvas_getrootfor(x), canvas_getrootfor(x)->gl_name->s_name, x);
         }
 */
-        else //pd_free(&x->gl_pd);
-			sys_vgui("pd {.x%lx menuclose -1;}\n", x);
+        else pd_free(&x->gl_pd);
+			//sys_queuegui(x, x, canvas_dofree);
+			//clock_delay(x->gl_destroy, 0);
     }
-    else if (force == 1)
+    else if (force == 1) {
         //pd_free(&x->gl_pd);
-		sys_vgui("pd {.x%lx menuclose -1;}\n", x);
+		//sys_vgui("pd {.x%lx menuclose -1;}\n", x);
+		//sys_vgui("menu_close .x%lx\n", x);
+		sys_queuegui(x, x, canvas_dofree);
+		//clock_delay(x->gl_destroy, 0);
+	}
     else if (force == 2)
     {
         canvas_dirty(x, 0);
@@ -2817,8 +2816,10 @@ void canvas_menuclose(t_canvas *x, t_floatarg fforce)
             //         canvas_getrootfor(x), g);
             return;
         }
-        else //pd_free(&x->gl_pd);
-			sys_vgui("pd {.x%lx menuclose -1;}\n", x);
+        else pd_free(&x->gl_pd);
+			//sys_vgui("pd {.x%lx menuclose -1;}\n", x);
+			//sys_queuegui(x, x, canvas_dofree);
+			//clock_delay(x->gl_destroy, 0);
     }
     else if (force == 3)
     {
diff --git a/src/m_class.c b/src/m_class.c
index 3278f85da3dbe0e08b878985dd27bc0e30a8ba7b..abb9561cce6b0ca8f7e416d0cc8fe83867cc78d6 100644
--- a/src/m_class.c
+++ b/src/m_class.c
@@ -669,6 +669,8 @@ void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv)
     int narg = 0;
     t_pd *bonzo;
     
+	//fprinf(stderr,"\nstart %s %d\n", s->s_name, c->c_nmethod);
+
         /* check for messages that are handled by fixed slots in the class
         structure.  We don't catch "pointer" though so that sending "pointer"
         to pd_objectmaker doesn't require that we supply a pointer value. */
@@ -709,6 +711,7 @@ void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv)
         if (m->me_name == s)
 		//if (m && m->me_name == s)
     {
+		//fprintf(stderr,"me_name %s\n", m->me_name);
         wp = m->me_arg;
         if (*wp == A_GIMME)
         {
diff --git a/src/m_pd.h b/src/m_pd.h
index a1cd59fd1a46f3ab2f63c6e7f7f00857b3f1663c..b61e370a2202bb42761dcf1546221cab340466fb 100644
--- a/src/m_pd.h
+++ b/src/m_pd.h
@@ -11,7 +11,7 @@ extern "C" {
 #define PD_MAJOR_VERSION 0
 #define PD_MINOR_VERSION 42
 #define PD_BUGFIX_VERSION 5
-#define PD_TEST_VERSION "extended-l2ork-20110324"
+#define PD_TEST_VERSION "extended-l2ork-20110326"
 
 /* old name for "MSW" flag -- we have to take it for the sake of many old
 "nmakefiles" for externs, which will define NT and not MSW */
diff --git a/src/pd.tk b/src/pd.tk
index a1b43e55cf3d45251a0a3e37b16847fbfba67746..066472b387245f2157046b7e242ccee9cb957119 100644
--- a/src/pd.tk
+++ b/src/pd.tk
@@ -851,7 +851,7 @@ proc pdtk_check {canvas x message default} {
     if {! [string compare $answer yes]}  {
 		pd $message
 		if {$canvas eq "."} {
-			focus $canvassegfault due to the way iemgui's implementation of universal color
+			focus $canvas
 		} else {
 			menu_close $canvas
 		}
@@ -1545,6 +1545,7 @@ proc menu_print {name} {
 }
 
 proc menu_close {name} {
+	#puts stderr menu_close
 	if {$name == ".texteditor.text"} { 
 		set topname [string trimright $name .text]
 		texteditor_send $name
@@ -1989,7 +1990,7 @@ proc pdtk_canvas_new {name width height geometry editable} {
         -xscrollcommand "$name.scrollhort set" \
         -scrollregion [concat 0 0 $width $height]
 
-	pdtk_standardkeybindings $name.c
+	#pdtk_standardkeybindings $name.c
 
 	if {[info tclversion] >= 8.5 && $pd_nt == 0} {
 		if {$::menu($name) == 1} {
diff --git a/src/s_inter.c b/src/s_inter.c
index 6d0191a471f87828518db16808979b03f8d5324e..47eb6a530c816dfae5ca6b348817f596a2c17452 100644
--- a/src/s_inter.c
+++ b/src/s_inter.c
@@ -716,7 +716,7 @@ void sys_gui(char *s)
     sys_vgui("%s", s);
 }
 
-static int sys_flushtogui( void)
+int sys_flushtogui( void)
 {
     int writesize = sys_guibufhead - sys_guibuftail, nwrote = 0;
     if (writesize > 0)