diff --git a/src/iso2022.c b/src/iso2022.c
index 96092b5..99a7ee3 100644
--- a/src/iso2022.c
+++ b/src/iso2022.c
@@ -303,7 +303,7 @@ _vte_iso2022_is_ambiguous(gunichar c)
 		}
 	}
 	if (!ambiguous) {
-		ambiguous = g_hash_table_new (g_direct_hash, g_direct_equal);
+		ambiguous = g_hash_table_new (NULL, NULL);
 
 		for (i = 0; i < G_N_ELEMENTS(_vte_iso2022_ambiguous_chars); i++) {
 			p = GINT_TO_POINTER(_vte_iso2022_ambiguous_chars[i]);
diff --git a/src/vte-private.h b/src/vte-private.h
index 46c195f..3ed7214 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -338,11 +338,10 @@ struct _VteTerminalPrivate {
 	gboolean adjustment_changed_tag;
 
 	/* Background images/"transparency". */
-	gboolean bg_update_pending;
+	guint bg_update_pending;
 	gboolean bg_transparent;
 	GdkPixbuf *bg_pixbuf;
 	char *bg_file;
-	guint bg_update_tag;
 	GdkColor bg_tint_color;
 	long bg_saturation;	/* out of VTE_SATURATION_MAX */
 	guint16 bg_opacity;
diff --git a/src/vte.c b/src/vte.c
index f18b507..b4aaeec 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -28,6 +28,7 @@ #ifdef HAVE_SYS_SYSLIMITS_H
 #include <sys/syslimits.h>
 #endif
 #include <glib.h>
+#include <glib/gstdio.h>
 #include <glib-object.h>
 #include <gdk/gdk.h>
 #include <gdk/gdkkeysyms.h>
@@ -183,27 +184,32 @@ #endif
 void
 _vte_terminal_set_default_attributes(VteTerminal *terminal)
 {
+	VteScreen *screen;
+
 	g_assert(VTE_IS_TERMINAL(terminal));
-	terminal->pvt->screen->defaults.c = ' ';
-	terminal->pvt->screen->defaults.columns = 1;
-	terminal->pvt->screen->defaults.fragment = 0;
-	terminal->pvt->screen->defaults.empty = 1;
-	terminal->pvt->screen->defaults.fore = VTE_DEF_FG;
-	terminal->pvt->screen->defaults.back = VTE_DEF_BG;
-	terminal->pvt->screen->defaults.reverse = 0;
-	terminal->pvt->screen->defaults.bold = 0;
-	terminal->pvt->screen->defaults.invisible = 0;
-	terminal->pvt->screen->defaults.protect = 0;
-	terminal->pvt->screen->defaults.standout = 0;
-	terminal->pvt->screen->defaults.underline = 0;
-	terminal->pvt->screen->defaults.strikethrough = 0;
-	terminal->pvt->screen->defaults.half = 0;
-	terminal->pvt->screen->defaults.blink = 0;
+
+	screen = terminal->pvt->screen;
+
+	screen->defaults.c = ' ';
+	screen->defaults.columns = 1;
+	screen->defaults.fragment = 0;
+	screen->defaults.empty = 1;
+	screen->defaults.fore = VTE_DEF_FG;
+	screen->defaults.back = VTE_DEF_BG;
+	screen->defaults.reverse = 0;
+	screen->defaults.bold = 0;
+	screen->defaults.invisible = 0;
+	screen->defaults.protect = 0;
+	screen->defaults.standout = 0;
+	screen->defaults.underline = 0;
+	screen->defaults.strikethrough = 0;
+	screen->defaults.half = 0;
+	screen->defaults.blink = 0;
 	/* Alternate charset isn't an attribute, though we treat it as one.
-	 * terminal->pvt->screen->defaults.alternate = 0; */
-	terminal->pvt->screen->basic_defaults = terminal->pvt->screen->defaults;
-	terminal->pvt->screen->color_defaults = terminal->pvt->screen->defaults;
-	terminal->pvt->screen->fill_defaults = terminal->pvt->screen->defaults;
+	 * screen->defaults.alternate = 0; */
+	screen->basic_defaults = screen->defaults;
+	screen->color_defaults = screen->defaults;
+	screen->fill_defaults = screen->defaults;
 }
 
 static gboolean
@@ -862,8 +868,7 @@ vte_terminal_set_default_tabstops(VteTer
 	if (terminal->pvt->tabstops != NULL) {
 		g_hash_table_destroy(terminal->pvt->tabstops);
 	}
-	terminal->pvt->tabstops = g_hash_table_new(g_direct_hash,
-						   g_direct_equal);
+	terminal->pvt->tabstops = g_hash_table_new(NULL, NULL);
 	width = _vte_termcap_find_numeric(terminal->pvt->termcap,
 					  terminal->pvt->emulation,
 					  "it");
@@ -1570,11 +1575,12 @@ void
 vte_terminal_set_encoding(VteTerminal *terminal, const char *codeset)
 {
 	const char *old_codeset;
-	GQuark encoding_quark;
 	VteConv conv;
 	char *obuf1, *obuf2;
 	gsize bytes_written;
 
+	g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
 	old_codeset = terminal->pvt->encoding;
 	if (codeset == NULL) {
 		g_get_charset(&codeset);
@@ -1597,8 +1603,7 @@ vte_terminal_set_encoding(VteTerminal *t
 	terminal->pvt->outgoing_conv = conv;
 
 	/* Set the terminal's encoding to the new value. */
-	encoding_quark = g_quark_from_string(codeset);
-	terminal->pvt->encoding = g_quark_to_string(encoding_quark);
+	terminal->pvt->encoding = g_intern_string(codeset);
 
 	/* Convert any buffered output bytes. */
 	if ((_vte_buffer_length(terminal->pvt->outgoing) > 0) &&
@@ -2165,6 +2170,7 @@ vte_terminal_set_colors(VteTerminal *ter
 void
 vte_terminal_set_opacity(VteTerminal *terminal, guint16 opacity)
 {
+	g_return_if_fail(VTE_IS_TERMINAL(terminal));
 	terminal->pvt->bg_opacity = opacity;
 }
 
@@ -2178,6 +2184,7 @@ vte_terminal_set_opacity(VteTerminal *te
 void
 vte_terminal_set_default_colors(VteTerminal *terminal)
 {
+	g_return_if_fail(VTE_IS_TERMINAL(terminal));
 	vte_terminal_set_colors(terminal, NULL, NULL, NULL, 0);
 }
 
@@ -2876,7 +2883,7 @@ vte_terminal_emit_pending_text_signals(V
 	if (quark != 0) {
 		for (i = 0; i < G_N_ELEMENTS(non_visual_quarks); i++) {
 			if (non_visual_quarks[i].quark == 0) {
-				tmp = g_quark_from_string(non_visual_quarks[i].name);
+				tmp = g_quark_from_static_string(non_visual_quarks[i].name);
 				non_visual_quarks[i].quark = tmp;
 			}
 			if (quark == non_visual_quarks[i].quark) {
@@ -3584,7 +3591,6 @@ static void
 vte_terminal_feed_child_using_modes(VteTerminal *terminal,
 				    const char *data, glong length)
 {
-	g_assert(VTE_IS_TERMINAL(terminal));
 	if (length == ((gssize)-1)) {
 		length = strlen(data);
 	}
@@ -3695,7 +3701,6 @@ static void
 vte_terminal_hierarchy_changed(GtkWidget *widget, GtkWidget *old_toplevel,
 			       gpointer data)
 {
-	VteTerminal *terminal;
 	GtkWidget *toplevel;
 
 #ifdef VTE_DEBUG
@@ -3704,19 +3709,17 @@ #ifdef VTE_DEBUG
 	}
 #endif
 
-	terminal = VTE_TERMINAL(widget);
-
 	if (old_toplevel != NULL) {
 		g_signal_handlers_disconnect_by_func(old_toplevel,
 						     vte_terminal_configure_toplevel,
-						     terminal);
+						     widget);
 	}
 
 	toplevel = gtk_widget_get_toplevel(widget);
 	if (toplevel != NULL) {
 		g_signal_connect(toplevel, "configure-event",
 				 G_CALLBACK(vte_terminal_configure_toplevel),
-				 terminal);
+				 widget);
 	}
 }
 
@@ -4386,6 +4389,7 @@ vte_terminal_send_mouse_button_internal(
 {
 	unsigned char cb = 0, cx = 0, cy = 0;
 	char buf[LINE_MAX];
+	gint len;
 
 	/* Encode the button information in cb. */
 	switch (button) {
@@ -4428,8 +4432,8 @@ vte_terminal_send_mouse_button_internal(
 			1, terminal->row_count);;
 
 	/* Send event direct to the child, this is binary not text data */
-	snprintf(buf, sizeof(buf), _VTE_CAP_CSI "M%c%c%c", cb, cx, cy);
-	vte_terminal_feed_child_binary(terminal, buf, strlen(buf));
+	len = g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "M%c%c%c", cb, cx, cy);
+	vte_terminal_feed_child_binary(terminal, buf, len);
 }
 
 /* Send a mouse button click/release notification. */
@@ -4482,6 +4486,7 @@ vte_terminal_maybe_send_mouse_drag(VteTe
 {
 	unsigned char cb = 0, cx = 0, cy = 0;
 	char buf[LINE_MAX];
+	gint len;
 
 	/* First determine if we even want to send notification. */
 	switch (event->type) {
@@ -4552,8 +4557,8 @@ vte_terminal_maybe_send_mouse_drag(VteTe
 			1, terminal->row_count);;
 
 	/* Send event direct to the child, this is binary not text data */
-	snprintf(buf, sizeof(buf), "%sM%c%c%c", _VTE_CAP_CSI, cb, cx, cy);
-	vte_terminal_feed_child_binary(terminal, buf, strlen(buf));
+	len = g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "M%c%c%c", cb, cx, cy);
+	vte_terminal_feed_child_binary(terminal, buf, len);
 }
 
 /* Clear all match hilites. */
@@ -6082,7 +6087,7 @@ #endif
 	return FALSE;
 }
 
-static gint
+static gboolean
 vte_terminal_visibility_notify(GtkWidget *widget, GdkEventVisibility *event)
 {
 	VteTerminal *terminal;
@@ -6238,6 +6243,7 @@ void
 vte_terminal_set_font(VteTerminal *terminal,
 		      const PangoFontDescription *font_desc)
 {
+	g_return_if_fail(VTE_IS_TERMINAL(terminal));
 	vte_terminal_set_font_full(terminal, font_desc,
 				   VTE_ANTI_ALIAS_USE_DEFAULT);
 }
@@ -6278,6 +6284,8 @@ vte_terminal_set_font_from_string_full(V
 void
 vte_terminal_set_font_from_string(VteTerminal *terminal, const char *name)
 {
+	g_return_if_fail(VTE_IS_TERMINAL(terminal));
+	g_return_if_fail(name != NULL);
 	vte_terminal_set_font_from_string_full(terminal, name,
 					       VTE_ANTI_ALIAS_USE_DEFAULT);
 }
@@ -6329,7 +6337,6 @@ vte_terminal_refresh_size(VteTerminal *t
 void
 vte_terminal_set_size(VteTerminal *terminal, glong columns, glong rows)
 {
-	struct winsize size;
 	g_return_if_fail(VTE_IS_TERMINAL(terminal));
 #ifdef VTE_DEBUG
 	if (_vte_debug_on(VTE_DEBUG_MISC)) {
@@ -6338,20 +6345,17 @@ #ifdef VTE_DEBUG
 	}
 #endif
 	if (terminal->pvt->pty_master != -1) {
-		memset(&size, 0, sizeof(size));
-		size.ws_row = rows;
-		size.ws_col = columns;
 		/* Try to set the terminal size. */
 		if (_vte_pty_set_size(terminal->pvt->pty_master, columns, rows) != 0) {
 			g_warning(_("Error setting PTY size: %s."),
 				    strerror(errno));
 		}
+		/* Read the terminal size, in case something went awry. */
+		vte_terminal_refresh_size(terminal);
 	} else {
 		terminal->row_count = rows;
 		terminal->column_count = columns;
 	}
-	/* Read the terminal size, in case something went awry. */
-	vte_terminal_refresh_size(terminal);
 	/* Our visible text changed. */
 	vte_terminal_emit_text_modified(terminal);
 }
@@ -6364,7 +6368,8 @@ vte_terminal_handle_scroll(VteTerminal *
 	VteScreen *screen;
 
 	/* Sanity checks. */
-	if (GTK_WIDGET_REALIZED(terminal) == FALSE) {
+	if (GTK_WIDGET_DRAWABLE(terminal) == FALSE ||
+			terminal->pvt->visibility_state == GDK_VISIBILITY_FULLY_OBSCURED) {
 		return;
 	}
 
@@ -6405,7 +6410,7 @@ vte_terminal_set_scroll_adjustment(VteTe
 		if (terminal->adjustment != NULL) {
 			/* Disconnect our signal handlers from this object. */
 			g_signal_handlers_disconnect_by_func(terminal->adjustment,
-							     (gpointer)vte_terminal_handle_scroll,
+							     vte_terminal_handle_scroll,
 							     terminal);
 			g_object_unref(terminal->adjustment);
 		}
@@ -6414,7 +6419,7 @@ vte_terminal_set_scroll_adjustment(VteTe
 
 		/* We care about the offset, not the top or bottom. */
 		g_signal_connect_swapped(terminal->adjustment,
-					 "value_changed",
+					 "value-changed",
 					 G_CALLBACK(vte_terminal_handle_scroll),
 					 terminal);
 	}
@@ -6434,14 +6439,14 @@ void
 vte_terminal_set_emulation(VteTerminal *terminal, const char *emulation)
 {
 	int columns, rows;
-	GQuark quark;
+
+	g_return_if_fail(VTE_IS_TERMINAL(terminal));
 
 	/* Set the emulation type, for reference. */
 	if (emulation == NULL) {
 		emulation = vte_terminal_get_default_emulation(terminal);
 	}
-	quark = g_quark_from_string(emulation);
-	terminal->pvt->emulation = g_quark_to_string(quark);
+	terminal->pvt->emulation = g_intern_string(emulation);
 #ifdef VTE_DEBUG
 	if (_vte_debug_on(VTE_DEBUG_MISC)) {
 		g_printerr("Setting emulation to `%s'...", emulation);
@@ -6527,23 +6532,22 @@ vte_terminal_set_termcap(VteTerminal *te
 {
 	struct stat st;
 	char *wpath;
-	GQuark q = 0;
 
 	if (path == NULL) {
 		wpath = g_strdup_printf(DATADIR "/" PACKAGE "/termcap/%s",
 					terminal->pvt->emulation ?
 					terminal->pvt->emulation :
 					vte_terminal_get_default_emulation(terminal));
-		if (stat(wpath, &st) != 0) {
+		if (g_stat(wpath, &st) != 0) {
 			g_free(wpath);
 			wpath = g_strdup("/etc/termcap");
 		}
-		q = g_quark_from_string(wpath);
+		path = g_intern_string (wpath);
 		g_free(wpath);
 	} else {
-		q = g_quark_from_string(path);
+		path = g_intern_string (path);
 	}
-	terminal->pvt->termcap_path = g_quark_to_string(q);
+	terminal->pvt->termcap_path = path;
 
 #ifdef VTE_DEBUG
 	if (_vte_debug_on(VTE_DEBUG_MISC)) {
@@ -6707,7 +6711,7 @@ #endif
 	/* Load the termcap data and set up the emulation. */
 	pvt->keypad_mode = VTE_KEYMODE_NORMAL;
 	pvt->cursor_mode = VTE_KEYMODE_NORMAL;
-	pvt->dec_saved = g_hash_table_new(g_direct_hash, g_direct_equal);
+	pvt->dec_saved = g_hash_table_new(NULL, NULL);
 	pvt->default_column_count = 80;
 	pvt->default_row_count = 24;
 
@@ -6718,7 +6722,7 @@ #endif
 	vte_terminal_set_size(terminal,
 			      pvt->default_column_count,
 			      pvt->default_row_count);
-	pvt->pty_master = -1;
+	g_assert (pvt->pty_master == -1);
 	pvt->pty_input_source = VTE_INVALID_SOURCE;
 	pvt->pty_output_source = VTE_INVALID_SOURCE;
 	pvt->pty_pid = -1;
@@ -6726,7 +6730,7 @@ #endif
 	/* Set up I/O encodings. */
 	pvt->iso2022 = _vte_iso2022_state_new(pvt->encoding,
 					      &_vte_terminal_codeset_changed_cb,
-					      (gpointer)terminal);
+					      terminal);
 	pvt->incoming = _vte_buffer_new();
 	pvt->pending = g_array_new(FALSE, FALSE, sizeof(gunichar));
 	pvt->cursor_blink_tag = VTE_INVALID_SOURCE;
@@ -6791,7 +6795,7 @@ #endif
 	vte_terminal_connect_xft_settings(terminal);
 
 	/* Set up background information. */
-	pvt->bg_update_tag = VTE_INVALID_SOURCE;
+	pvt->bg_update_pending = VTE_INVALID_SOURCE;
 	pvt->bg_tint_color.red = 0;
 	pvt->bg_tint_color.green = 0;
 	pvt->bg_tint_color.blue = 0;
@@ -6865,7 +6869,7 @@ vte_terminal_size_allocate(GtkWidget *wi
 	VteTerminal *terminal;
 	glong width, height;
 	gint x, y, w, h;
-	gboolean snapped_to_bottom;
+	gboolean snapped_to_bottom, repaint;
 
 #ifdef VTE_DEBUG
 	if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
@@ -6890,6 +6894,8 @@ #ifdef VTE_DEBUG
 			width, height);
 	}
 #endif
+	repaint = widget->allocation.width != allocation->width ||
+		widget->allocation.height != allocation->height;
 
 	/* Set our allocation to match the structure. */
 	widget->allocation = *allocation;
@@ -6915,18 +6921,13 @@ #endif
 
 	/* Resize the GDK window. */
 	if (widget->window != NULL) {
-		gdk_window_get_geometry(widget->window,
-					&x, &y, &w, &h, NULL);
 		gdk_window_move_resize(widget->window,
 				       allocation->x,
 				       allocation->y,
 				       allocation->width,
 				       allocation->height);
-		/* Repaint if we were resized or moved. */
-		if ((x != allocation->x) ||
-		    (y != allocation->y) ||
-		    (w != allocation->width) ||
-		    (h != allocation->height)) {
+		/* Repaint if we were resized. */
+		if (repaint) {
 			_vte_invalidate_all(terminal);
 		}
 	}
@@ -7057,10 +7058,9 @@ #endif
 	terminal->pvt->cursor_blink_state = FALSE;
 
 	/* Cancel any pending background updates. */
-	if (terminal->pvt->bg_update_tag != VTE_INVALID_SOURCE) {
-		g_source_remove(terminal->pvt->bg_update_tag);
-		terminal->pvt->bg_update_tag = VTE_INVALID_SOURCE;
-		terminal->pvt->bg_update_pending = FALSE;
+	if (terminal->pvt->bg_update_pending != VTE_INVALID_SOURCE) {
+		g_source_remove(terminal->pvt->bg_update_pending);
+		terminal->pvt->bg_update_pending = VTE_INVALID_SOURCE;
 	}
 
 	/* Cancel any pending redraws. */
@@ -7102,8 +7102,9 @@ #endif
 	}
 
 	/* Free background info. */
-	if (terminal->pvt->bg_update_tag != VTE_INVALID_SOURCE) {
-		g_source_remove(terminal->pvt->bg_update_tag);
+	if (terminal->pvt->bg_update_pending != VTE_INVALID_SOURCE) {
+		g_source_remove(terminal->pvt->bg_update_pending);
+		terminal->pvt->bg_update_pending = VTE_INVALID_SOURCE;
 		g_free(terminal->pvt->bg_file);
 	}
 
@@ -7324,11 +7325,6 @@ #ifdef VTE_DEBUG
 		gdk_window_set_debug_updates(TRUE);
 	}
 #endif
-	gdk_window_move_resize(widget->window,
-			       widget->allocation.x,
-			       widget->allocation.y,
-			       widget->allocation.width,
-			       widget->allocation.height);
 	gdk_window_set_user_data(widget->window, widget);
 	gdk_window_show(widget->window);
 
@@ -7451,28 +7447,30 @@ vte_terminal_determine_colors(VteTermina
 	}
 
 	/* Handle invisible, bold, and standout text by adjusting colors. */
-	if (cell && cell->invisible) {
-		*fore = *back;
-	}
-	if (cell && cell->bold) {
-		if (*fore == VTE_DEF_FG) {
-			*fore = VTE_BOLD_FG;
-		} else
-		if ((*fore != VTE_DEF_BG) && (*fore < VTE_LEGACY_COLOR_SET_SIZE)) {
-			*fore += VTE_COLOR_BRIGHT_OFFSET;
+	if (cell) {
+		if (cell->invisible) {
+			*fore = *back;
 		}
-	}
-	if (cell && cell->half) {
-		if (*fore == VTE_DEF_FG) {
-			*fore = VTE_DIM_FG;
-		} else
-		if ((*fore < VTE_LEGACY_COLOR_SET_SIZE)) {
-			*fore = corresponding_dim_index[*fore];;
+		if (cell->bold) {
+			if (*fore == VTE_DEF_FG) {
+				*fore = VTE_BOLD_FG;
+			} else
+			if ((*fore != VTE_DEF_BG) && (*fore < VTE_LEGACY_COLOR_SET_SIZE)) {
+				*fore += VTE_COLOR_BRIGHT_OFFSET;
+			}
 		}
-	}
-	if (cell && cell->standout) {
-		if (*back < VTE_LEGACY_COLOR_SET_SIZE) {
-			*back += VTE_COLOR_BRIGHT_OFFSET;
+		if (cell->half) {
+			if (*fore == VTE_DEF_FG) {
+				*fore = VTE_DIM_FG;
+			} else
+			if ((*fore < VTE_LEGACY_COLOR_SET_SIZE)) {
+				*fore = corresponding_dim_index[*fore];;
+			}
+		}
+		if (cell->standout) {
+			if (*back < VTE_LEGACY_COLOR_SET_SIZE) {
+				*back += VTE_COLOR_BRIGHT_OFFSET;
+			}
 		}
 	}
 }
@@ -10032,9 +10030,8 @@ #endif
 
 	/* Note that the update has finished. */
 	if (terminal->pvt->bg_update_pending) {
-		terminal->pvt->bg_update_pending = FALSE;
-		g_source_remove(terminal->pvt->bg_update_tag);
-		terminal->pvt->bg_update_tag = VTE_INVALID_SOURCE;
+		g_source_remove(terminal->pvt->bg_update_pending);
+		terminal->pvt->bg_update_pending = VTE_INVALID_SOURCE;
 	}
 
 	/* Force a redraw for everything. */
@@ -10051,8 +10048,7 @@ static void
 vte_terminal_queue_background_update(VteTerminal *terminal)
 {
 	if (!terminal->pvt->bg_update_pending) {
-		terminal->pvt->bg_update_pending = TRUE;
-		terminal->pvt->bg_update_tag =
+		terminal->pvt->bg_update_pending =
 				g_idle_add_full(VTE_FX_PRIORITY,
 						(GSourceFunc)vte_terminal_background_update,
 						terminal,
@@ -10159,11 +10155,14 @@ #ifdef VTE_DEBUG
 			transparent ? "on" : "off");
 	}
 #endif
-	/* Save this background type. */
-	terminal->pvt->bg_transparent = transparent;
+	transparent = !!transparent;
+	if(transparent != terminal->pvt->bg_transparent) {
+		/* Save this background type. */
+		terminal->pvt->bg_transparent = transparent;
 
-	/* Update the background. */
-	vte_terminal_queue_background_update(terminal);
+		/* Update the background. */
+		vte_terminal_queue_background_update(terminal);
+	}
 }
 
 /**
@@ -10297,6 +10296,7 @@ vte_terminal_set_cursor_blinks(VteTermin
 {
 	g_return_if_fail(VTE_IS_TERMINAL(terminal));
 
+	blink = !!blink;
 	if (terminal->pvt->cursor_blinks == blink)
 		return;
 
@@ -10338,6 +10338,9 @@ vte_terminal_set_scrollback_lines(VteTer
 	lines = MAX(lines, VTE_SCROLLBACK_MIN);
 	lines = MAX(lines, terminal->row_count);
 
+	if (terminal->pvt->scrollback_lines == lines)
+		return;
+
 	/* We need to resize both scrollback buffers, and this beats copying
 	 * and pasting the same code twice. */
 	screens[0] = &terminal->pvt->normal_screen;
@@ -10607,8 +10610,7 @@ vte_terminal_reset(VteTerminal *terminal
 	/* Reset saved settings. */
 	if (terminal->pvt->dec_saved != NULL) {
 		g_hash_table_destroy(terminal->pvt->dec_saved);
-		terminal->pvt->dec_saved = g_hash_table_new(g_direct_hash,
-							    g_direct_equal);
+		terminal->pvt->dec_saved = g_hash_table_new(NULL, NULL);
 	}
 	/* Reset the color palette. */
 	/* vte_terminal_set_default_colors(terminal); */
@@ -10911,6 +10913,10 @@ vte_terminal_set_pty(VteTerminal *termin
 
        g_return_if_fail(VTE_IS_TERMINAL(terminal));
 
+       if (pty_master == terminal->pvt->pty_master) {
+	       return;
+       }
+
        if (terminal->pvt->pty_master != -1) {
                _vte_pty_close(terminal->pvt->pty_master);
                close(terminal->pvt->pty_master);
@@ -10920,9 +10926,9 @@ vte_terminal_set_pty(VteTerminal *termin
 
        /* Set the pty to be non-blocking. */
        i = fcntl(terminal->pvt->pty_master, F_GETFL);
-	   if ((i & O_NONBLOCK) == 0) {
-		   fcntl(terminal->pvt->pty_master, F_SETFL, i | O_NONBLOCK);
-	   }
+       if ((i & O_NONBLOCK) == 0) {
+	       fcntl(terminal->pvt->pty_master, F_SETFL, i | O_NONBLOCK);
+       }
 
        vte_terminal_set_size(terminal,
                              terminal->column_count,
diff --git a/src/vteseq.c b/src/vteseq.c
index 5074aed..b6f2282 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -2456,8 +2456,7 @@ vte_sequence_handler_st(VteTerminal *ter
 			GValueArray *params)
 {
 	if (terminal->pvt->tabstops == NULL) {
-		terminal->pvt->tabstops = g_hash_table_new(g_direct_hash,
-							   g_direct_equal);
+		terminal->pvt->tabstops = g_hash_table_new(NULL, NULL);
 	}
 	_vte_terminal_set_tabstop(terminal,
 				 terminal->pvt->screen->cursor_current.col);
@@ -2644,23 +2643,19 @@ vte_sequence_handler_vb(VteTerminal *ter
 			GValueArray *params)
 {
 	GtkWidget *widget;
-	gint width, height, state;
 
 	widget = &terminal->widget;
 	if (GTK_WIDGET_REALIZED(widget)) {
-		gdk_drawable_get_size(widget->window, &width, &height);
-		state = GTK_WIDGET_STATE(widget);
 		/* Fill the screen with the default foreground color, and then
 		 * repaint everything, to provide visual bell. */
 		gdk_draw_rectangle(widget->window,
-				   widget->style->fg_gc[state],
+				   widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
 				   TRUE,
 				   0, 0,
-				   width, height);
+				   widget->allocation.width, widget->allocation.height);
 		gdk_window_process_updates(widget->window, TRUE);
 		/* Force the repaint. */
-		_vte_invalidate_all(terminal);
-		gdk_window_process_updates(widget->window, TRUE);
+		_vte_invalidate_all(terminal); /* max delay of UPDATE_REPEAT_TIMEOUT */
 	}
 	return FALSE;
 }
@@ -3532,6 +3527,7 @@ vte_sequence_handler_device_status_repor
 	VteScreen *screen;
 	long param;
 	char buf[LINE_MAX];
+	gint len;
 
 	screen = terminal->pvt->screen;
 
@@ -3541,17 +3537,18 @@ vte_sequence_handler_device_status_repor
 		switch (param) {
 		case 5:
 			/* Send a thumbs-up sequence. */
-			snprintf(buf, sizeof(buf), "%s%dn", _VTE_CAP_CSI, 0);
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal,
+				       	_VTE_CAP_CSI "0n",
+				       	sizeof(_VTE_CAP_CSI "0n")-1);
 			break;
 		case 6:
 			/* Send the cursor position. */
-			snprintf(buf, sizeof(buf),
-				 "%s%ld;%ldR", _VTE_CAP_CSI,
+			len = g_snprintf(buf, sizeof(buf),
+				 _VTE_CAP_CSI "%ld;%ldR",
 				 screen->cursor_current.row + 1 -
 				 screen->insert_delta,
 				 screen->cursor_current.col + 1);
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal, buf, len);
 			break;
 		default:
 			break;
@@ -3571,6 +3568,7 @@ vte_sequence_handler_dec_device_status_r
 	VteScreen *screen;
 	long param;
 	char buf[LINE_MAX];
+	gint len;
 
 	screen = terminal->pvt->screen;
 
@@ -3580,30 +3578,33 @@ vte_sequence_handler_dec_device_status_r
 		switch (param) {
 		case 6:
 			/* Send the cursor position. */
-			snprintf(buf, sizeof(buf),
-				 "%s?%ld;%ldR", _VTE_CAP_CSI,
+			len = g_snprintf(buf, sizeof(buf),
+				 _VTE_CAP_CSI "?%ld;%ldR",
 				 screen->cursor_current.row + 1 -
 				 screen->insert_delta,
 				 screen->cursor_current.col + 1);
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal, buf, len);
 			break;
 		case 15:
 			/* Send printer status -- 10 = ready,
 			 * 11 = not ready.  We don't print. */
-			snprintf(buf, sizeof(buf), "%s?%dn", _VTE_CAP_CSI, 11);
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal, 
+					_VTE_CAP_CSI "?11n",
+					sizeof(_VTE_CAP_CSI "?11n")-1);
 			break;
 		case 25:
 			/* Send UDK status -- 20 = locked,
 			 * 21 = not locked.  I don't even know what
 			 * that means, but punt anyway. */
-			snprintf(buf, sizeof(buf), "%s?%dn", _VTE_CAP_CSI, 20);
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal, 
+					_VTE_CAP_CSI "?20n",
+					sizeof(_VTE_CAP_CSI "?20n")-1);
 			break;
 		case 26:
 			/* Send keyboard status.  50 = no locator. */
-			snprintf(buf, sizeof(buf), "%s?%dn", _VTE_CAP_CSI, 50);
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal, 
+					_VTE_CAP_CSI "?50n",
+					sizeof(_VTE_CAP_CSI "?50n")-1);
 			break;
 		default:
 			break;
@@ -3741,6 +3742,7 @@ vte_sequence_handler_window_manipulation
 	char buf[LINE_MAX];
 	long param, arg1, arg2;
 	guint width, height, i;
+	gint len;
 
 	widget = &terminal->widget;
 	screen = terminal->pvt->screen;
@@ -3878,8 +3880,8 @@ #endif
 			break;
 		case 11:
 			/* If we're unmapped, then we're iconified. */
-			snprintf(buf, sizeof(buf),
-				 "%s%dt", _VTE_CAP_CSI,
+			len = g_snprintf(buf, sizeof(buf),
+				 _VTE_CAP_CSI "%dt",
 				 1 + !GTK_WIDGET_MAPPED(widget));
 #ifdef VTE_DEBUG
 			if (_vte_debug_on(VTE_DEBUG_PARSE)) {
@@ -3888,14 +3890,14 @@ #ifdef VTE_DEBUG
 					"non-iconified" : "iconified");
 			}
 #endif
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal, buf, len);
 			break;
 		case 13:
 			/* Send window location, in pixels. */
 			gdk_window_get_origin(widget->window,
 					      &width, &height);
-			snprintf(buf, sizeof(buf),
-				 "%s%d;%dt", _VTE_CAP_CSI,
+			len = g_snprintf(buf, sizeof(buf),
+				 _VTE_CAP_CSI "%d;%dt",
 				 width + VTE_PAD_WIDTH, height + VTE_PAD_WIDTH);
 #ifdef VTE_DEBUG
 			if (_vte_debug_on(VTE_DEBUG_PARSE)) {
@@ -3904,16 +3906,14 @@ #ifdef VTE_DEBUG
 					width, height);
 			}
 #endif
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal, buf, len);
 			break;
 		case 14:
 			/* Send window size, in pixels. */
-			gdk_drawable_get_size(widget->window,
-					      &width, &height);
-			snprintf(buf, sizeof(buf),
-				 "%s%d;%dt", _VTE_CAP_CSI,
-				 height - 2 * VTE_PAD_WIDTH,
-				 width - 2 * VTE_PAD_WIDTH);
+			len = g_snprintf(buf, sizeof(buf),
+				 _VTE_CAP_CSI "%d;%dt",
+				 widget->allocation.height - 2 * VTE_PAD_WIDTH,
+				 widget->allocation.width - 2 * VTE_PAD_WIDTH);
 #ifdef VTE_DEBUG
 			if (_vte_debug_on(VTE_DEBUG_PARSE)) {
 				g_printerr("Reporting window size "
@@ -3922,7 +3922,7 @@ #ifdef VTE_DEBUG
 					height - 2 * VTE_PAD_WIDTH);
 			}
 #endif
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal, buf, len);
 			break;
 		case 18:
 			/* Send widget size, in cells. */
@@ -3931,11 +3931,11 @@ #ifdef VTE_DEBUG
 				g_printerr("Reporting widget size.\n");
 			}
 #endif
-			snprintf(buf, sizeof(buf),
-				 "%s%ld;%ldt", _VTE_CAP_CSI,
+			len = g_snprintf(buf, sizeof(buf),
+				 _VTE_CAP_CSI "%ld;%ldt",
 				 terminal->row_count,
 				 terminal->column_count);
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal, buf, len);
 			break;
 		case 19:
 #ifdef VTE_DEBUG
@@ -3950,11 +3950,11 @@ #endif
 			}
 			height = gdk_screen_get_height(gscreen);
 			width = gdk_screen_get_width(gscreen);
-			snprintf(buf, sizeof(buf),
-				 "%s%ld;%ldt", _VTE_CAP_CSI,
+			len = g_snprintf(buf, sizeof(buf),
+				 _VTE_CAP_CSI "%ld;%ldt",
 				 height / terminal->char_height,
 				 width / terminal->char_width);
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal, buf, len);
 			break;
 		case 20:
 			/* Report the icon title. */
@@ -3963,12 +3963,9 @@ #ifdef VTE_DEBUG
 				g_printerr("Reporting icon title.\n");
 			}
 #endif
-			snprintf(buf, sizeof(buf),
-				 "%sL%s%s",
-				 _VTE_CAP_OSC,
-				 "Terminal",
-				 _VTE_CAP_ST);
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal,
+				 _VTE_CAP_OSC "LTerminal" _VTE_CAP_ST,
+				 sizeof(_VTE_CAP_OSC "LTerminal" _VTE_CAP_ST));
 			break;
 		case 21:
 			/* Report the window title. */
@@ -3977,12 +3974,9 @@ #ifdef VTE_DEBUG
 				g_printerr("Reporting window title.\n");
 			}
 #endif
-			snprintf(buf, sizeof(buf),
-				 "%sL%s%s",
-				 _VTE_CAP_OSC,
-				 "Terminal",
-				 _VTE_CAP_ST);
-			vte_terminal_feed_child(terminal, buf, strlen(buf));
+			vte_terminal_feed_child(terminal,
+				 _VTE_CAP_OSC "Terminal" _VTE_CAP_ST,
+				 sizeof(_VTE_CAP_OSC "Terminal" _VTE_CAP_ST));
 			break;
 		default:
 			if (param >= 24) {
