Index: commands.c
===================================================================
--- commands.c	(revision 8dfb59c5c626b7869a6588008de13f8bb6cbb54d)
+++ commands.c	(revision 38cc669c974b1e74b508ce3558022ddfdb71cbb5)
@@ -2566,9 +2566,9 @@
   /* if we get two arguments, ask for the password */
   if (argc==2) {
+    owl_function_start_password("AIM Password: ");
     owl_editwin_set_cbdata(owl_global_get_typwin(&g),
                            owl_strdup(argv[1]), owl_free);
     owl_editwin_set_callback(owl_global_get_typwin(&g),
                              owl_callback_aimlogin);
-    owl_function_start_password("AIM Password: ");
     return(NULL);
   } else {
@@ -2699,10 +2699,8 @@
   }
 
-  owl_editwin_fullclear(e);
   owl_global_set_needrefresh(&g);
+  owl_global_pop_context(&g);
+
   owl_global_set_typwin_inactive(&g);
-  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
-
-  owl_global_pop_context(&g);
 }
 
@@ -2761,8 +2759,9 @@
   owl_history_store(hist, owl_editwin_get_text(e));
   owl_history_reset(hist);
+  cmd = owl_strdup(owl_editwin_get_text(e));
+
   owl_global_set_typwin_inactive(&g);
   owl_global_pop_context(&g);
-  cmd = owl_strdup(owl_editwin_get_text(e));
-  owl_editwin_fullclear(e);
+
   rv = owl_function_command(cmd);
   owl_free(cmd);
@@ -2783,5 +2782,5 @@
   owl_global_set_typwin_inactive(&g);
   owl_global_pop_context(&g);
-  owl_editwin_fullclear(e);
+
   owl_global_set_needrefresh(&g);
 }
@@ -2796,6 +2795,5 @@
 
   owl_function_run_buffercommand();
-  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
-  owl_editwin_fullclear(e);
+
   owl_global_set_typwin_inactive(&g);
   owl_global_pop_context(&g);
Index: editwin.c
===================================================================
--- editwin.c	(revision 8dfb59c5c626b7869a6588008de13f8bb6cbb54d)
+++ editwin.c	(revision 38cc669c974b1e74b508ce3558022ddfdb71cbb5)
@@ -64,5 +64,5 @@
 #define WHITESPACE " \n\t"
 
-owl_editwin *owl_editwin_allocate(void)
+static owl_editwin *owl_editwin_allocate(void)
 {
   owl_editwin *e;
@@ -80,4 +80,5 @@
     oe_release_excursion(e, e->excursions);
   }
+  oe_destroy_cbdata(e);
 
   owl_free(e);
@@ -116,8 +117,10 @@
 }
 
-/* initialize the editwin e.
- * 'win' is an already initialzed curses window that will be used by editwin
- */
-void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
+static void _owl_editwin_init(owl_editwin *e,
+                              WINDOW *win,
+                              int winlines,
+                              int wincols,
+                              int style,
+                              owl_history *hist)
 {
   e->buff=owl_malloc(INCR);
@@ -148,4 +151,12 @@
 }
 
+owl_editwin *owl_editwin_new(WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
+{
+  owl_editwin *e = owl_editwin_allocate();
+
+  _owl_editwin_init(e, win, winlines, wincols, style, hist);
+  return e;
+}
+
 void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols)
 {
@@ -249,31 +260,4 @@
 }
 
-void owl_editwin_new_style(owl_editwin *e, int newstyle, owl_history *h)
-{
-  e->hist = h;
-
-  if (e->style==newstyle) return;
-
-  if (newstyle==OWL_EDITWIN_STYLE_MULTILINE) {
-    e->style=newstyle;
-  } else if (newstyle==OWL_EDITWIN_STYLE_ONELINE) {
-    e->style=newstyle;
-
-    /* nuke everything after the first line */
-    owl_editwin_move_to_top(e);
-    owl_editwin_move_to_end_of_line(e);
-    owl_editwin_replace(e, oe_count_glyphs(e->buff + e->index),  "");
-  }
-}
-
-/* completly reinitialize the buffer */
-void owl_editwin_fullclear(owl_editwin *e)
-{
-  owl_free(e->buff);
-  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
-  e->callback = NULL;
-  oe_destroy_cbdata(e);
-}
-
 /* clear all text except for locktext and put the cursor at the
  * beginning
@@ -294,5 +278,5 @@
 
   owl_free(e->buff);
-  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
+  _owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
 
   if (lock > 0) {
Index: functions.c
===================================================================
--- functions.c	(revision 8dfb59c5c626b7869a6588008de13f8bb6cbb54d)
+++ functions.c	(revision 38cc669c974b1e74b508ce3558022ddfdb71cbb5)
@@ -283,8 +283,7 @@
 
   /* create and setup the editwin */
+  owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_MULTILINE,
+                               owl_global_get_msg_history(&g));
   e = owl_global_get_typwin(&g);
-  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE,
-			owl_global_get_msg_history(&g));
-  owl_editwin_clear(e);
   owl_editwin_set_dotsend(e);
   s = owl_sprintf("----> %s\n", line);
@@ -292,9 +291,6 @@
   owl_free(s);
 
-  /* make it active */
-  owl_global_set_typwin_active(&g);
-
-  owl_editwin_set_cbdata(owl_global_get_typwin(&g), data, cleanup);
-  owl_editwin_set_callback(owl_global_get_typwin(&g), callback);
+  owl_editwin_set_cbdata(e, data, cleanup);
+  owl_editwin_set_callback(e, callback);
   owl_global_push_context(&g, OWL_CTX_EDITMULTI, e, "editmulti");
 }
@@ -1913,8 +1909,6 @@
   owl_editwin *tw;
 
+  owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
   tw=owl_global_get_typwin(&g);
-  owl_global_set_typwin_active(&g);
-  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, 
-			owl_global_get_cmd_history(&g));
 
   owl_editwin_set_locktext(tw, "command: ");
@@ -1931,7 +1925,6 @@
   owl_editwin *tw;
 
+  owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
   tw=owl_global_get_typwin(&g);
-  owl_global_set_typwin_active(&g);
-  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
 
   owl_editwin_set_locktext(tw, line);
@@ -1947,7 +1940,6 @@
   owl_editwin *tw;
 
-  tw=owl_global_get_typwin(&g);
-  owl_global_set_typwin_active(&g);
-  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
+  owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
+  tw = owl_global_get_typwin(&g);
   owl_editwin_set_echochar(tw, '*');
 
Index: global.c
===================================================================
--- global.c	(revision 8dfb59c5c626b7869a6588008de13f8bb6cbb54d)
+++ global.c	(revision 38cc669c974b1e74b508ce3558022ddfdb71cbb5)
@@ -45,6 +45,5 @@
   g->rightshift=0;
 
-  g->tw = owl_editwin_allocate();
-  owl_editwin_init(g->tw, NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
+  g->tw = NULL;
 
   owl_keyhandler_init(&g->kh);
@@ -171,5 +170,6 @@
   _owl_panel_set_window(&g->typpan, newwin(typwin_lines, cols, g->recwinlines+2, 0));
 
-  owl_editwin_set_curswin(g->tw, owl_global_get_curs_typwin(g), typwin_lines, g->cols);
+  if (g->tw)
+      owl_editwin_set_curswin(g->tw, owl_global_get_curs_typwin(g), typwin_lines, g->cols);
 
   idlok(owl_global_get_curs_typwin(g), FALSE);
@@ -368,9 +368,15 @@
 }
 
-void owl_global_set_typwin_active(owl_global *g) {
-  int d = owl_global_get_typewindelta(g);
+void owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) {
+  int d;
+  d = owl_global_get_typewindelta(g);
   if (d > 0)
       owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
 
+  g->tw = owl_editwin_new(owl_global_get_curs_typwin(g),
+                          owl_global_get_typwin_lines(g),
+                          g->cols,
+                          style,
+                          hist);
   g->typwinactive=1;
 }
@@ -382,4 +388,8 @@
 
   g->typwinactive=0;
+
+  owl_editwin_delete(g->tw);
+  werase(owl_global_get_curs_typwin(g));
+  g->tw = NULL;
 }
 
@@ -513,5 +523,6 @@
   owl_mainwin_redisplay(&(g->mw));
   sepbar(NULL);
-  owl_editwin_redisplay(g->tw);
+  if (g->tw)
+      owl_editwin_redisplay(g->tw);
   owl_function_full_redisplay();
 
Index: perlglue.xs
===================================================================
--- perlglue.xs	(revision 1b1cd2cda4440db58f76fdfc5a6f5ab697a2bdf5)
+++ perlglue.xs	(revision 38cc669c974b1e74b508ce3558022ddfdb71cbb5)
@@ -549,6 +549,13 @@
 	int count;
 	const char *string;
-	CODE:
-		RETVAL = owl_editwin_replace(owl_global_get_typwin(&g), count, string);
+	PREINIT:
+		owl_editwin *e;
+	CODE:
+		e = owl_global_get_typwin(&g);
+		if (e) {
+			RETVAL = owl_editwin_replace(e, count, string);
+		} else {
+			RETVAL = 0;
+		}
 	OUTPUT:
 		RETVAL
@@ -557,6 +564,13 @@
 point_move(delta)
 	int delta;
-	CODE:
-		RETVAL = owl_editwin_point_move(owl_global_get_typwin(&g), delta);
+	PREINIT:
+		owl_editwin *e;
+	CODE:
+		e = owl_global_get_typwin(&g);
+		if (e) {
+			RETVAL = owl_editwin_point_move(e, delta);
+		} else {
+			RETVAL = 0;
+		}
 	OUTPUT:
 		RETVAL
@@ -565,6 +579,13 @@
 replace_region(string)
 	const char *string;
-	CODE:
-		RETVAL = owl_editwin_replace_region(owl_global_get_typwin(&g), string);
+	PREINIT:
+		owl_editwin *e;
+	CODE:
+		e = owl_global_get_typwin(&g);
+		if (e) {
+			RETVAL = owl_editwin_replace_region(e, string);
+		} else {
+			RETVAL = 0;
+		}
 	OUTPUT:
 		RETVAL
@@ -574,6 +595,12 @@
 	PREINIT:
 		char *region;
-	CODE:
-		region = owl_editwin_get_region(owl_global_get_typwin(&g));
+		owl_editwin *e;
+	CODE:
+		e = owl_global_get_typwin(&g);
+		if (e) {
+			region = owl_editwin_get_region(owl_global_get_typwin(&g));
+		} else {
+			region = NULL;
+		}
 		RETVAL = region;
 	OUTPUT:
@@ -588,7 +615,12 @@
 	PREINIT:
 		int count;
+		owl_editwin *e;
 		owl_editwin_excursion *x;
 	CODE:
 	{
+		e = owl_global_get_typwin(&g);
+		if(!e)
+			croak("The edit window is not currently active!");
+
 		x = owl_editwin_begin_excursion(owl_global_get_typwin(&g));
 		PUSHMARK(SP);
@@ -612,6 +644,13 @@
 int
 current_column()
-	CODE:
-		RETVAL = owl_editwin_current_column(owl_global_get_typwin(&g));
+	PREINIT:
+		owl_editwin *e;
+	CODE:
+		e = owl_global_get_typwin(&g);
+		if (e) {
+			RETVAL = owl_editwin_current_column(e);
+		} else {
+			RETVAL = 0;
+		}
 	OUTPUT:
 		RETVAL
@@ -619,6 +658,13 @@
 int
 point()
-	CODE:
-		RETVAL = owl_editwin_get_point(owl_global_get_typwin(&g));
+	PREINIT:
+		owl_editwin *e;
+	CODE:
+		e = owl_global_get_typwin(&g);
+		if (e) {
+			RETVAL = owl_editwin_get_point(e);
+		} else {
+			RETVAL = 0;
+		}
 	OUTPUT:
 		RETVAL
@@ -626,6 +672,13 @@
 int
 mark()
-	CODE:
-		RETVAL = owl_editwin_get_mark(owl_global_get_typwin(&g));
-	OUTPUT:
-		RETVAL
+	PREINIT:
+		owl_editwin *e;
+	CODE:
+		e = owl_global_get_typwin(&g);
+		if (e) {
+			RETVAL = owl_editwin_get_mark(e);
+		} else {
+			RETVAL = 0;
+		}
+	OUTPUT:
+		RETVAL
