Index: README
===================================================================
--- README	(revision aeadc748f353cd0be4ebfa805d85577c9c7498fa)
+++ README	(revision 13ee8f2b200092c55bc8af13b46ca948c16dcd94)
@@ -18,4 +18,5 @@
 BarnOwl currently requires the following perl modules off of CPAN:
 
+AnyEvent
 PAR
 Net::DNS
@@ -30,5 +31,5 @@
 The IRC module requires:
 
-Net::IRC
+AnyEvent::IRC
 Class::Accessor
 
Index: cmd.c
===================================================================
--- cmd.c	(revision f25df21f6284aedd48c098bc68cee9896da5ce98)
+++ cmd.c	(revision 4c7c21f786a0416a755645b78db0b851f75f8748)
@@ -12,12 +12,11 @@
 
 int owl_cmddict_setup(owl_cmddict *cd) {
-  if (0 != owl_cmddict_init(cd)) return(-1);
+  owl_cmddict_init(cd);
   if (0 != owl_cmddict_add_from_list(cd, commands_to_init)) return(-1);
   return(0);
 }
 
-int owl_cmddict_init(owl_cmddict *cd) {
-  if (owl_dict_create(cd)) return(-1);
-  return(0);
+void owl_cmddict_init(owl_cmddict *cd) {
+  owl_dict_create(cd);
 }
 
@@ -99,18 +98,11 @@
 
 char *owl_cmddict_execute_argv(const owl_cmddict *cd, const owl_context *ctx, const char *const *argv, int argc) {
-  GString *buf = g_string_new("");
-  int i;
-  char *retval;
-
-  /* We weren't given a command line, so fabricate a valid one. */
-  for(i = 0; i < argc; i++) {
-    if (i != 0)
-      g_string_append_c(buf, ' ');
-    owl_string_append_quoted_arg(buf, argv[i]);
-  }
-
-  retval = _owl_cmddict_execute(cd, ctx, argv, argc, buf->str);
-
-  g_string_free(buf, true);
+  char *buff;
+  char *retval = NULL;
+
+  buff = g_strjoinv(" ", (char**)argv);
+  retval = _owl_cmddict_execute(cd, ctx, argv, argc, buff);
+  g_free(buff);
+
   return retval;
 }
@@ -142,9 +134,9 @@
 void owl_cmd_cleanup(owl_cmd *cmd)
 {
-  if (cmd->name) g_free(cmd->name);
-  if (cmd->summary) g_free(cmd->summary);
-  if (cmd->usage) g_free(cmd->usage);
-  if (cmd->description) g_free(cmd->description);
-  if (cmd->cmd_aliased_to) g_free(cmd->cmd_aliased_to);
+  g_free(cmd->name);
+  g_free(cmd->summary);
+  g_free(cmd->usage);
+  g_free(cmd->description);
+  g_free(cmd->cmd_aliased_to);
   if (cmd->cmd_perl) owl_perlconfig_cmd_cleanup(cmd);
 }
Index: commands.c
===================================================================
--- commands.c	(revision c809f5e8a3cc2745724f518c89b09279b5508b02)
+++ commands.c	(revision 3b8a563ae4e07b1064fe005714793565ac720dc4)
@@ -1288,5 +1288,5 @@
   }
   owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
-  if (filter) g_free(filter);
+  g_free(filter);
   return(NULL);
 }
@@ -1318,5 +1318,5 @@
   }
   owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
-  if (filter) g_free(filter);
+  g_free(filter);
   return(NULL);
 }
@@ -1691,7 +1691,5 @@
   commands = g_strsplit_set(newbuff, ";", 0);
   for (i = 0; commands[i] != NULL; i++) {
-    if (lastrv) {
-      g_free(lastrv);
-    }
+    g_free(lastrv);
     lastrv = owl_function_command(commands[i]);
   }
Index: configure.ac
===================================================================
--- configure.ac	(revision 125536565b016a2dc0130569f6192cfebbe39f49)
+++ configure.ac	(revision 125536565b016a2dc0130569f6192cfebbe39f49)
@@ -115,5 +115,5 @@
 
 dnl Add CFLAGS and LIBS for glib-2.0
-PKG_CHECK_MODULES(GLIB,[glib-2.0 gobject-2.0 gthread-2.0])
+PKG_CHECK_MODULES(GLIB,[glib-2.0 >= 2.12 gobject-2.0 gthread-2.0])
 
 AC_MSG_NOTICE([Adding glib-2.0 CFLAGS ${GLIB_CFLAGS}])
Index: dict.c
===================================================================
--- dict.c	(revision f25df21f6284aedd48c098bc68cee9896da5ce98)
+++ dict.c	(revision 4c7c21f786a0416a755645b78db0b851f75f8748)
@@ -15,10 +15,8 @@
 #define GROWBY 3 / 2
 
-int owl_dict_create(owl_dict *d) {
+void owl_dict_create(owl_dict *d) {
   d->size=0;
   d->els=g_new(owl_dict_el, INITSIZE);
   d->avail=INITSIZE;
-  if (d->els==NULL) return(-1);
-  return(0);
 }
 
@@ -60,12 +58,9 @@
 /* Appends dictionary keys to a list.  Duplicates the keys,
  * so they will need to be freed by the caller. */
-int owl_dict_get_keys(const owl_dict *d, owl_list *l) {
+void owl_dict_get_keys(const owl_dict *d, owl_list *l) {
   int i;
-  char *dupk;
   for (i=0; i<d->size; i++) {
-    if ((dupk = g_strdup(d->els[i].k)) == NULL) return(-1);
-    owl_list_append_element(l, dupk);
+    owl_list_append_element(l, g_strdup(d->els[i].k));
   }
-  return(0);
 }
 
@@ -84,5 +79,4 @@
 {
   int pos, found;
-  char *dupk;
   found = _owl_dict_find_pos(d, k, &pos);
   if (found && delete_on_replace) {
@@ -99,5 +93,4 @@
       if (d->els==NULL) return(-1);
     }
-    if ((dupk = g_strdup(k)) == NULL) return(-1);
     if (pos!=d->size) {
       /* shift forward to leave us a slot */
@@ -106,5 +99,5 @@
     }
     d->size++;
-    d->els[pos].k = dupk;
+    d->els[pos].k = g_strdup(k);
     d->els[pos].v = v;    
     return(0);
Index: editwin.c
===================================================================
--- editwin.c	(revision 47e0a6a50d1c08ec05030b2507b3f1a84b618a9f)
+++ editwin.c	(revision 3b8a563ae4e07b1064fe005714793565ac720dc4)
@@ -317,6 +317,5 @@
   }
 
-  if (locktext)
-    g_free(locktext);
+  g_free(locktext);
 
   oe_set_index(e, lock);
Index: fmtext.c
===================================================================
--- fmtext.c	(revision 4479497945518a0fe5ddc9e5cf08f98bc7990cd9)
+++ fmtext.c	(revision 7b4f3bea704ed82f2c36ba19fcf354d7442a5bb7)
@@ -184,14 +184,7 @@
 }
 
-static void _owl_fmtext_update_colorpair(short fg, short bg, short *pair)
-{
-  if (owl_global_get_hascolors(&g)) {
-    *pair = owl_fmtext_get_colorpair(fg, bg);
-  }
-}
-
 static void _owl_fmtext_wcolor_set(WINDOW *w, short pair)
 {
-  if (owl_global_get_hascolors(&g)) {
+  if (has_colors()) {
       wcolor_set(w,pair,NULL);
       wbkgdset(w, COLOR_PAIR(pair));
@@ -221,5 +214,5 @@
   bg = default_bgcolor;
   _owl_fmtext_wattrset(w, attr);
-  _owl_fmtext_update_colorpair(fg, bg, &pair);
+  pair = owl_fmtext_get_colorpair(fg, bg);
   _owl_fmtext_wcolor_set(w, pair);
 
@@ -270,5 +263,5 @@
       if (bg == OWL_COLOR_DEFAULT) bg = default_bgcolor;
       _owl_fmtext_wattrset(w, attr);
-      _owl_fmtext_update_colorpair(fg, bg, &pair);
+      pair = owl_fmtext_get_colorpair(fg, bg);
       _owl_fmtext_wcolor_set(w, pair);
 
@@ -662,5 +655,4 @@
            continue */
       } else if (!strcasecmp(buff, "@color") 
-                 && owl_global_get_hascolors(&g)
                  && owl_global_is_colorztext(&g)) {
         g_free(buff);
@@ -820,5 +812,5 @@
     }
   }
-  if (owl_global_get_hascolors(&g)) {
+  if (has_colors()) {
     for(i = 0; i < 8; i++) {
       short fg, bg;
@@ -835,4 +827,7 @@
   owl_colorpair_mgr *cpmgr;
   short pair;
+
+  if (!has_colors())
+    return 0;
 
   /* Sanity (Bounds) Check */
@@ -852,5 +847,5 @@
   if (!(pair != -1 && pair < cpmgr->next)) {
     /* If we didn't find a pair, search for a free one to assign. */
-    pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;
+    pair = (cpmgr->next < owl_util_get_colorpairs()) ? cpmgr->next : -1;
     if (pair != -1) {
       /* We found a free pair, initialize it. */
Index: functions.c
===================================================================
--- functions.c	(revision 47128d939b8cf3c9833095b626efc1efcee0744f)
+++ functions.c	(revision 47128d939b8cf3c9833095b626efc1efcee0744f)
@@ -32,5 +32,5 @@
   char *rv;
   rv=owl_function_command(cmdbuff);
-  if (rv) g_free(rv);
+  g_free(rv);
 }
 
@@ -453,5 +453,5 @@
 
   if (rv || status) {
-    if(cryptmsg) g_free(cryptmsg);
+    g_free(cryptmsg);
     g_free(old_msg);
     owl_function_error("Error in zcrypt, possibly no key found.  Message not sent.");
@@ -991,5 +991,5 @@
   /* execute the commands in shutdown */
   ret = owl_perlconfig_execute("BarnOwl::Hooks::_shutdown();");
-  if (ret) g_free(ret);
+  g_free(ret);
 
   /* signal our child process, if any */
@@ -1817,7 +1817,7 @@
 	  owl_global_get_cols(&g));
 
-  if (owl_global_get_hascolors(&g)) {
+  if (has_colors()) {
     owl_fmtext_append_normal(&fm, "Color: Yes\n");
-    owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g));
+    owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_util_get_colorpairs());
     owl_fmtext_appendf_normal(&fm, "Can change colors: %s\n", can_change_color() ? "yes" : "no");
   } else {
@@ -2226,9 +2226,7 @@
     f = fl->data;
     owl_fmtext_append_normal(&fm, "   ");
-    if (owl_global_get_hascolors(&g)) {
-      owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_fgcolor(f), owl_filter_get_bgcolor(f));
-    } else {
-      owl_fmtext_append_normal(&fm, owl_filter_get_name(f));
-    }
+    owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f),
+                                   owl_filter_get_fgcolor(f),
+                                   owl_filter_get_bgcolor(f));
     owl_fmtext_append_normal(&fm, "\n");
   }
@@ -2360,7 +2358,5 @@
 done:
   g_free(class);
-  if (instance) {
-    g_free(instance);
-  }
+  g_free(instance);
   return(filtname);
 }
@@ -2523,5 +2519,5 @@
 
   filtname = g_strdup_printf("conversation-%s", ccs);
-  owl_text_tr(filtname, ' ', '-');
+  g_strdelimit(filtname, " ", '-');
 
   if (owl_global_get_filter(&g, filtname)) {
@@ -2959,5 +2955,5 @@
   
   if (viewsize==0) {
-    owl_function_error("No messages present");
+    owl_function_makemsg("No messages present");
     return;
   }
@@ -2973,5 +2969,5 @@
   /* bounds check */
   if (start>=viewsize || start<0) {
-    owl_function_error("No further matches found");
+    owl_function_makemsg("No further matches found");
     return;
   }
@@ -3002,5 +2998,5 @@
   }
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
-  owl_function_error("No matches found");
+  owl_function_makemsg("No matches found");
 }
 
Index: global.c
===================================================================
--- global.c	(revision dc1edbded39e57c67e8049c2960f0c235cd5afb5)
+++ global.c	(revision dc1edbded39e57c67e8049c2960f0c235cd5afb5)
@@ -54,8 +54,4 @@
   g->direction=OWL_DIRECTION_DOWNWARDS;
   g->zaway=0;
-  if (has_colors()) {
-    g->hascolors=1;
-  }
-  g->colorpairs=COLOR_PAIRS;
   owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
   g->debug=OWL_DEBUG;
@@ -512,5 +508,5 @@
 
 void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
-  if (g->startupargs) g_free(g->startupargs);
+  g_free(g->startupargs);
   g->startupargs = g_strjoinv(" ", argv);
 }
@@ -577,17 +573,4 @@
 owl_view *owl_global_get_current_view(owl_global *g) {
   return(&(g->current_view));
-}
-
-/* has colors */
-
-int owl_global_get_hascolors(const owl_global *g) {
-  if (g->hascolors) return(1);
-  return(0);
-}
-
-/* color pairs */
-
-int owl_global_get_colorpairs(const owl_global *g) {
-  return(g->colorpairs);
 }
 
@@ -773,6 +756,6 @@
 }
 
-int owl_global_get_style_names(const owl_global *g, owl_list *l) {
-  return owl_dict_get_keys(&(g->styledict), l);
+void owl_global_get_style_names(const owl_global *g, owl_list *l) {
+  owl_dict_get_keys(&(g->styledict), l);
 }
 
Index: keybinding.c
===================================================================
--- keybinding.c	(revision d07af84683f667d7c34814c1b0a12823b08f6df0)
+++ keybinding.c	(revision 3b8a563ae4e07b1064fe005714793565ac720dc4)
@@ -69,7 +69,7 @@
 void owl_keybinding_delete(owl_keybinding *kb)
 {
-  if (kb->keys) g_free(kb->keys);
-  if (kb->desc) g_free(kb->desc);
-  if (kb->command) g_free(kb->command);
+  g_free(kb->keys);
+  g_free(kb->desc);
+  g_free(kb->command);
   g_free(kb);
 }
Index: keymap.c
===================================================================
--- keymap.c	(revision 47e0a6a50d1c08ec05030b2507b3f1a84b618a9f)
+++ keymap.c	(revision 4c7c21f786a0416a755645b78db0b851f75f8748)
@@ -9,7 +9,7 @@
 {
   if (!name || !desc) return(-1);
-  if ((km->name = g_strdup(name)) == NULL) return(-1);
-  if ((km->desc = g_strdup(desc)) == NULL) return(-1);
-  if (0 != owl_list_create(&km->bindings)) return(-1);
+  km->name = g_strdup(name);
+  km->desc = g_strdup(desc);
+  owl_list_create(&km->bindings);
   km->parent = NULL;
   km->default_fn = default_fn;
@@ -179,10 +179,9 @@
 /* NOTE: keyhandler has private access to the internals of keymap */
 
-int owl_keyhandler_init(owl_keyhandler *kh)
-{
-  if (0 != owl_dict_create(&kh->keymaps)) return(-1); 
+void owl_keyhandler_init(owl_keyhandler *kh)
+{
+  owl_dict_create(&kh->keymaps);
   kh->active = NULL;
   owl_keyhandler_reset(kh);
-  return(0);
 }
 
Index: list.c
===================================================================
--- list.c	(revision ddbbcffae8064f4d266a9735a16225e4feef1a3c)
+++ list.c	(revision fda61d3fe64381f30e32bc0091ab5ab59d95524f)
@@ -5,11 +5,9 @@
 #define GROWBY 3 / 2
 
-int owl_list_create(owl_list *l)
+void owl_list_create(owl_list *l)
 {
   l->size=0;
   l->list=g_new(void *, INITSIZE);
   l->avail=INITSIZE;
-  if (l->list==NULL) return(-1);
-  return(0);
 }
 
Index: logging.c
===================================================================
--- logging.c	(revision fe3b017371488552616f09bfed6345a51e6fe0fa)
+++ logging.c	(revision 7865479440dd042766ecbbc1119b45e5eb7cd6a6)
@@ -151,5 +151,5 @@
   } else if (owl_message_is_type_jabber(m)) {
     to = g_strdup_printf("jabber:%s", owl_message_get_recipient(m));
-    owl_text_tr(to, '/', '_');
+    g_strdelimit(to, "/", '_');
   } else if (owl_message_is_type_aim(m)) {
     char *temp2;
Index: owl.c
===================================================================
--- owl.c	(revision 1d21d9fd6efdecb79b0bef96aabee3943d6a955a)
+++ owl.c	(revision 1d21d9fd6efdecb79b0bef96aabee3943d6a955a)
@@ -41,5 +41,4 @@
   char *confdir;
   bool debug;
-  bool rm_debug;
 } owl_options;
 
@@ -50,5 +49,4 @@
   fprintf(stderr, "  -n,--no-subs        don't load zephyr subscriptions\n");
   fprintf(stderr, "  -d,--debug          enable debugging\n");
-  fprintf(stderr, "  -D,--remove-debug   enable debugging and delete previous debug file\n");
   fprintf(stderr, "  -v,--version        print the Barnowl version number and exit\n");
   fprintf(stderr, "  -h,--help           print this help message\n");
@@ -66,5 +64,4 @@
     { "tty",             1, 0, 't' },
     { "debug",           0, 0, 'd' },
-    { "remove-debug",    0, 0, 'D' },
     { "version",         0, 0, 'v' },
     { "help",            0, 0, 'h' },
@@ -88,7 +85,4 @@
       opts->tty = g_strdup(optarg);
       break;
-    case 'D':
-      opts->rm_debug = 1;
-      /* fallthrough */
     case 'd':
       opts->debug = 1;
@@ -509,5 +503,4 @@
   /* owl global init */
   owl_global_init(&g);
-  if (opts.rm_debug) unlink(OWL_DEBUG_FILE);
   if (opts.debug) owl_global_set_debug_on(&g);
   if (opts.confdir) owl_global_set_confdir(&g, opts.confdir);
@@ -577,5 +570,5 @@
   owl_function_debugmsg("startup: executing perl startup, if applicable");
   perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();");
-  if (perlout) g_free(perlout);
+  g_free(perlout);
 
   /* welcome message */
Index: owl.h
===================================================================
--- owl.h	(revision dc1edbded39e57c67e8049c2960f0c235cd5afb5)
+++ owl.h	(revision dc1edbded39e57c67e8049c2960f0c235cd5afb5)
@@ -66,4 +66,5 @@
 #include "window.h"
 
+#ifndef OWL_VERSION_STRING
 #ifdef  GIT_VERSION
 #define stringify(x)       __stringify(x)
@@ -73,4 +74,5 @@
 #define OWL_VERSION_STRING PACKAGE_VERSION
 #endif
+#endif /* !OWL_VERSION_STRING */
 
 /* Feature that is being tested to redirect stderr through a pipe. 
@@ -602,6 +604,4 @@
   char *startupargs;
   int nextmsgid;
-  int hascolors;
-  int colorpairs;
   owl_colorpair_mgr cpmgr;
   pid_t newmsgproc_pid;
Index: perl/lib/BarnOwl.pm
===================================================================
--- perl/lib/BarnOwl.pm	(revision b120bd3c1bd6d9da691c8e4f11a3a1ba56d34c83)
+++ perl/lib/BarnOwl.pm	(revision f2d71cfa06117d6e28806432db20b584c4596a19)
@@ -38,4 +38,8 @@
 use BarnOwl::Completion;
 use BarnOwl::Help;
+use BarnOwl::AnyEvent;
+
+unshift @AnyEvent::REGISTRY, [BarnOwl => BarnOwl::AnyEvent::];
+require AnyEvent;
 
 use List::Util qw(max);
Index: perl/lib/BarnOwl/AnyEvent.pm
===================================================================
--- perl/lib/BarnOwl/AnyEvent.pm	(revision 21bab95d0968516d39d01ad621819e0be316e181)
+++ perl/lib/BarnOwl/AnyEvent.pm	(revision 21bab95d0968516d39d01ad621819e0be316e181)
@@ -0,0 +1,42 @@
+use strict;
+use warnings;
+package BarnOwl::AnyEvent;
+use BarnOwl::Timer;
+
+sub io {
+    my ($class, %arg) = @_;
+    my $fd = fileno($arg{fh});
+    my $mode = $arg{poll};
+    my $cb = $arg{cb};
+    my $self = {cb => $cb,
+                mode => $mode,
+                fd => $fd };
+    bless($self, $class);
+    $self->{dispatch} = BarnOwl::add_io_dispatch($fd, $mode, $cb);
+    return $self;
+}
+
+sub BarnOwl::AnyEvent::io::DESTROY
+{
+    my ($self) = @_;
+    BarnOwl::remove_io_dispatch($self->{fd});
+}
+
+sub timer {
+    my ($class, %arg) = @_;
+    return BarnOwl::Timer->new(\%arg);
+}
+
+sub DESTROY { }
+
+# sub idle {
+#     my ($class, %arg) = @_;
+#     my $cb = $arg{cb};
+# }
+
+# sub child {
+#     my ($class, %arg) = @_;
+#     my $cb = $arg{cb};
+# }
+
+1;
Index: perl/modules/IRC/lib/BarnOwl/Message/IRC.pm
===================================================================
--- perl/modules/IRC/lib/BarnOwl/Message/IRC.pm	(revision e04b7a18dd7a84eace5694f556a164a5128333a6)
+++ perl/modules/IRC/lib/BarnOwl/Message/IRC.pm	(revision 60b49a7d6017a553f86ef3036247a58587f313b9)
@@ -66,4 +66,5 @@
 sub action {shift->{action}}
 sub reason {shift->{reason}}
+sub old_nick {shift->{old_nick}};
 
 # display
@@ -80,8 +81,10 @@
 }
 
-sub login_extra { 
+sub login_extra {
     my $self = shift;
     if ($self->action eq "quit") {
         return $self->reason;
+    } elsif ($self->action eq 'nick change') {
+        return "was: " . $self->old_nick;
     } else {
         return $self->channel;
Index: perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
===================================================================
--- perl/modules/IRC/lib/BarnOwl/Module/IRC.pm	(revision 9620c8d92ecfed30b4b6c4d5d6861179e2ab418d)
+++ perl/modules/IRC/lib/BarnOwl/Module/IRC.pm	(revision 5c6d661cb25bf113e3f1b18aaed92753a61a9f96)
@@ -20,5 +20,5 @@
 use BarnOwl::Module::IRC::Completion;
 
-use Net::IRC;
+use AnyEvent::IRC;
 use Getopt::Long;
 use Encode;
@@ -30,6 +30,4 @@
 # Hash alias -> BarnOwl::Module::IRC::Connection object
 our %ircnets;
-our %channels;
-our %reconnect;
 
 sub startup {
@@ -70,5 +68,4 @@
 
     register_commands();
-    register_handlers();
     BarnOwl::filter(qw{irc type ^IRC$ or ( type ^admin$ and adminheader ^IRC$ )});
 }
@@ -76,5 +73,5 @@
 sub shutdown {
     for my $conn (values %ircnets) {
-        $conn->conn->disconnect();
+        $conn->conn->disconnect('Quitting');
     }
 }
@@ -98,6 +95,5 @@
         $list .= "\n";
 
-        for my $chan (keys %channels) {
-            next unless grep $_ eq $conn, @{$channels{$chan}};
+        for my $chan (keys %{$conn->conn->{channel_list}}) {
             $list .= "  $chan\n";
         }
@@ -105,28 +101,4 @@
 
     return $list;
-}
-
-#sub mainloop_hook {
-#    return unless defined $irc;
-#    eval {
-#        $irc->do_one_loop();
-#    };
-#    return;
-#}
-
-sub OwlProcess {
-    return unless defined $irc;
-    eval {
-        $irc->do_one_loop();
-    };
-    return;
-}
-
-
-sub register_handlers {
-    if(!$irc) {
-        $irc = Net::IRC->new;
-        $irc->timeout(0);
-    }
 }
 
@@ -406,21 +378,13 @@
     }
 
-    my $conn = BarnOwl::Module::IRC::Connection->new($irc, $alias,
-        Nick      => $nick,
-        Server    => $host,
-        Port      => $port,
-        Username  => $username,
-        Ircname   => $ircname,
-        Port      => $port,
-        Password  => $password,
-        SSL       => $ssl
-       );
-
-    if ($conn->conn->connected) {
-        $conn->connected("Connected to $alias as $nick");
-    } else {
-        die("IRC::Connection->connect failed: $!");
-    }
-
+    my $conn = BarnOwl::Module::IRC::Connection->new($alias, $host, $port, {
+        nick      => $nick,
+        user      => $username,
+        real      => $ircname,
+        password  => $password,
+        SSL       => $ssl,
+        timeout   => sub {0}
+       });
+    $ircnets{$alias} = $conn;
     return;
 }
@@ -429,10 +393,12 @@
     my $cmd = shift;
     my $conn = shift;
-    if ($conn->conn->connected) {
-        $conn->conn->disconnect;
-    } elsif ($reconnect{$conn->alias}) {
+    if ($conn->conn->{socket}) {
+        $conn->did_quit(1);
+        $conn->conn->disconnect("Goodbye!");
+    } elsif ($conn->{reconnect_timer}) {
         BarnOwl::admin_message('IRC',
                                "[" . $conn->alias . "] Reconnect cancelled");
         $conn->cancel_reconnect;
+        delete $ircnets{$conn->alias};
     }
 }
@@ -463,8 +429,8 @@
     for my $body (@msgs) {
 	if ($body =~ /^\/me (.*)/) {
-	    $conn->conn->me($to, Encode::encode('utf-8', $1));
+	    $conn->me($to, Encode::encode('utf-8', $1));
 	    $body = '* '.$conn->nick.' '.$1;
 	} else {
-	    $conn->conn->privmsg($to, Encode::encode('utf-8', $body));
+	    $conn->conn->send_msg('privmsg', $to, Encode::encode('utf-8', $body));
 	}
 	my $msg = BarnOwl::Message->new(
@@ -491,5 +457,5 @@
     my $target = shift;
     $target ||= shift;
-    $conn->conn->mode($target, @_);
+    $conn->conn->send_msg(mode => $target, @_);
     return;
 }
@@ -499,7 +465,5 @@
     my $conn = shift;
     my $chan = shift or die("Usage: $cmd channel\n");
-    $channels{$chan} ||= [];
-    push @{$channels{$chan}}, $conn;
-    $conn->conn->join($chan, @_);
+    $conn->conn->send_msg(join => $chan, @_);
     return;
 }
@@ -509,6 +473,5 @@
     my $conn = shift;
     my $chan = shift;
-    $channels{$chan} = [grep {$_ ne $conn} @{$channels{$chan} || []}];
-    $conn->conn->part($chan);
+    $conn->conn->send_msg(part => $chan);
     return;
 }
@@ -518,5 +481,5 @@
     my $conn = shift;
     my $nick = shift or die("Usage: $cmd <new nick>\n");
-    $conn->conn->nick($nick);
+    $conn->conn->send_msg(nick => $nick);
     return;
 }
@@ -527,5 +490,5 @@
     my $chan = shift;
     $conn->names_tmp([]);
-    $conn->conn->names($chan);
+    $conn->conn->send_msg(names => $chan);
     return;
 }
@@ -535,5 +498,5 @@
     my $conn = shift;
     my $who = shift || die("Usage: $cmd <user>\n");
-    $conn->conn->whois($who);
+    $conn->conn->send_msg(whois => $who);
     return;
 }
@@ -542,5 +505,5 @@
     my $cmd = shift;
     my $conn = shift;
-    $conn->conn->motd;
+    $conn->conn->send_msg('motd');
     return;
 }
@@ -560,6 +523,5 @@
     my $conn = shift;
     my $who = shift || die("Usage: $cmd <user>\n");
-    BarnOwl::error("WHO $cmd $conn $who");
-    $conn->conn->who($who);
+    $conn->conn->send_msg(who => $who);
     return;
 }
@@ -569,5 +531,5 @@
     my $conn = shift;
     my $type = shift || die("Usage: $cmd <chiklmouy> [server] \n");
-    $conn->conn->stats($type, @_);
+    $conn->conn->send_msg(stats => $type, @_);
     return;
 }
@@ -577,5 +539,5 @@
     my $conn = shift;
     my $chan = shift;
-    $conn->conn->topic($chan, @_ ? join(" ", @_) : undef);
+    $conn->conn->send_msg(topic => $chan, @_ ? join(" ", @_) : undef);
     return;
 }
@@ -584,5 +546,5 @@
     my $cmd = shift;
     my $conn = shift;
-    $conn->conn->sl(join(" ", @_));
+    $conn->conn->send_msg(@_);
     return;
 }
@@ -591,4 +553,15 @@
 ########################### Utilities/Helpers ##################################
 ################################################################################
+
+sub find_channel {
+    my $channel = shift;
+    my @found;
+    for my $conn (values %ircnets) {
+        if($conn->conn->{channel_list}{lc $channel}) {
+            push @found, $conn;
+        }
+    }
+    return $found[0] if(scalar @found == 1);
+}
 
 sub mk_irc_command {
@@ -614,7 +587,7 @@
             $channel = $ARGV[0];
             if(defined($channel) && $channel =~ /^#/) {
-                if($channels{$channel} && @{$channels{$channel}} == 1) {
+                if(my $c = find_channel($channel)) {
                     shift @ARGV;
-                    $conn = $channels{$channel}[0] unless $conn;
+                    $conn ||= $c;
                 }
             } elsif ($m && $m->type eq 'IRC' && !$m->is_private) {
@@ -654,7 +627,10 @@
     my $allow_disconnected = shift;
 
-    return $ircnets{$key} if exists $ircnets{$key};
-    return $reconnect{$key} if $allow_disconnected && exists $reconnect{$key};
-    die("No such ircnet: $key\n")
+    my $conn = $ircnets{$key};
+    die("No such ircnet: $key\n") unless $conn;
+    if ($conn->conn->{registered} || $allow_disconnected) {
+        return $conn;
+    }
+    die("[@{[$conn->alias]}] Not currently connected.");
 }
 
Index: perl/modules/IRC/lib/BarnOwl/Module/IRC/Completion.pm
===================================================================
--- perl/modules/IRC/lib/BarnOwl/Module/IRC/Completion.pm	(revision 955a36ef84bad0cfeb1e445598bf61de3856e4fb)
+++ perl/modules/IRC/lib/BarnOwl/Module/IRC/Completion.pm	(revision dace02afa8202c17375f083df8247cc4f9307dcb)
@@ -11,5 +11,13 @@
 sub complete_networks { keys %BarnOwl::Module::IRC::ircnets }
 sub complete_dests    { keys %users, complete_channels() }
-sub complete_channels { keys %BarnOwl::Module::IRC::channels }
+sub complete_channels {
+    my %channels;
+    for my $conn (values %BarnOwl::Module::IRC::ircnets) {
+        for my $chan (keys %{$conn->conn->{channel_list}}) {
+            $channels{$chan} = 1;
+        }
+    }
+    return keys %channels;
+}
 sub complete_nicks    { keys %users }
 sub complete_servers  { keys %servers }
Index: perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
===================================================================
--- perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm	(revision fb6e8e31c0b7bb318c002069222e2759783a9069)
+++ perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm	(revision 13ee8f2b200092c55bc8af13b46ca948c16dcd94)
@@ -11,70 +11,101 @@
 =head1 DESCRIPTION
 
-This module is a wrapper around Net::IRC::Connection for BarnOwl's IRC
+This module is a wrapper around AnyEvent::IRC::Client for BarnOwl's IRC
 support
 
 =cut
 
-use Net::IRC::Connection;
-
-use base qw(Class::Accessor Exporter);
-__PACKAGE__->mk_accessors(qw(conn alias channels motd names_tmp whois_tmp));
-our @EXPORT_OK = qw(&is_private);
+use AnyEvent::IRC::Client;
+use AnyEvent::IRC::Util qw(split_prefix prefix_nick encode_ctcp);
+
+use base qw(Class::Accessor);
+use Exporter 'import';
+__PACKAGE__->mk_accessors(qw(conn alias motd names_tmp whois_tmp
+                             server autoconnect_channels
+                             connect_args backoff did_quit));
+our @EXPORT_OK = qw(is_private);
 
 use BarnOwl;
 use Scalar::Util qw(weaken);
 
-BEGIN {
-    no strict 'refs';
-    my @delegate = qw(nick server);
-    for my $meth (@delegate) {
-        *{"BarnOwl::Module::IRC::Connection::$meth"} = sub {
-            shift->conn->$meth(@_);
-        }
-    }
-};
-
 sub new {
     my $class = shift;
-    my $irc = shift;
     my $alias = shift;
-    my %args = (@_);
-    my $conn = Net::IRC::Connection->new($irc, %args);
+    my $host  = shift;
+    my $port  = shift;
+    my $args  = shift;
+    my $nick = $args->{nick};
+    my $conn = AnyEvent::IRC::Client->new();
     my $self = bless({}, $class);
     $self->conn($conn);
+    $self->autoconnect_channels([]);
     $self->alias($alias);
-    $self->channels([]);
+    $self->server($host);
     $self->motd("");
     $self->names_tmp(0);
+    $self->backoff(0);
     $self->whois_tmp("");
-
-    $self->conn->add_default_handler(sub { shift; $self->on_event(@_) });
-    $self->conn->add_handler(['msg', 'notice', 'public', 'caction'],
-            sub { shift; $self->on_msg(@_) });
-    $self->conn->add_handler(['welcome', 'yourhost', 'created',
-                              'luserclient', 'luserop', 'luserchannels', 'luserme',
-                              'error'],
-            sub { shift; $self->on_admin_msg(@_) });
-    $self->conn->add_handler(['myinfo', 'map', 'n_local', 'n_global',
-            'luserconns'],
-            sub { });
-    $self->conn->add_handler(motdstart => sub { shift; $self->on_motdstart(@_) });
-    $self->conn->add_handler(motd      => sub { shift; $self->on_motd(@_) });
-    $self->conn->add_handler(endofmotd => sub { shift; $self->on_endofmotd(@_) });
-    $self->conn->add_handler(join      => sub { shift; $self->on_join(@_) });
-    $self->conn->add_handler(part      => sub { shift; $self->on_part(@_) });
-    $self->conn->add_handler(quit      => sub { shift; $self->on_quit(@_) });
-    $self->conn->add_handler(disconnect => sub { shift; $self->on_disconnect(@_) });
-    $self->conn->add_handler(nicknameinuse => sub { shift; $self->on_nickinuse(@_) });
-    $self->conn->add_handler(cping     => sub { shift; $self->on_ping(@_) });
-    $self->conn->add_handler(topic     => sub { shift; $self->on_topic(@_) });
-    $self->conn->add_handler(topicinfo => sub { shift; $self->on_topicinfo(@_) });
-    $self->conn->add_handler(namreply  => sub { shift; $self->on_namreply(@_) });
-    $self->conn->add_handler(endofnames=> sub { shift; $self->on_endofnames(@_) });
-    $self->conn->add_handler(endofwhois=> sub { shift; $self->on_endofwhois(@_) });
-    $self->conn->add_handler(mode      => sub { shift; $self->on_mode(@_) });
-    $self->conn->add_handler(nosuchchannel => sub { shift; $self->on_nosuchchannel(@_) });
+    $self->did_quit(0);
+
+    if(delete $args->{SSL}) {
+        $conn->enable_ssl;
+    }
+    $self->connect_args([$host, $port, $args]);
+    $conn->connect($host, $port, $args);
+    $conn->{heap}{parent} = $self;
+    weaken($conn->{heap}{parent});
+
+    sub on {
+        my $meth = "on_" . shift;
+        return sub {
+            my $conn = shift;
+            return unless $conn->{heap}{parent};
+            $conn->{heap}{parent}->$meth(@_);
+        }
+    }
+
+    # $self->conn->add_default_handler(sub { shift; $self->on_event(@_) });
+    $self->conn->reg_cb(registered => on("connect"),
+                        connfail   => sub { BarnOwl::error("Connection to $host failed!") },
+                        disconnect => on("disconnect"),
+                        publicmsg  => on("msg"),
+                        privatemsg => on("msg"),
+                        irc_error  => on("error"));
+    for my $m (qw(welcome yourhost created
+                  luserclient luserop luserchannels luserme
+                  error)) {
+        $self->conn->reg_cb("irc_$m" => on("admin_msg"));
+    }
+    $self->conn->reg_cb(irc_375       => on("motdstart"),
+                        irc_372       => on("motd"),
+                        irc_376       => on("endofmotd"),
+                        irc_join      => on("join"),
+                        irc_part      => on("part"),
+                        irc_quit      => on("quit"),
+                        irc_433       => on("nickinuse"),
+                        channel_topic => on("topic"),
+                        irc_333       => on("topicinfo"),
+                        irc_353       => on("namreply"),
+                        irc_366       => on("endofnames"),
+                        irc_311       => on("whois"),
+                        irc_312       => on("whois"),
+                        irc_319       => on("whois"),
+                        irc_320       => on("whois"),
+                        irc_318       => on("endofwhois"),
+                        irc_mode      => on("mode"),
+                        irc_401       => on("nosuch"),
+                        irc_402       => on("nosuch"),
+                        irc_403       => on("nosuch"),
+                        nick_change   => on("nick"),
+                        ctcp_action   => on("ctcp_action"),
+                        'irc_*' => sub { BarnOwl::debug("IRC: " . $_[1]->{command} . " " .
+                                                        join(" ", @{$_[1]->{params}})) });
 
     return $self;
+}
+
+sub nick {
+    my $self = shift;
+    return $self->conn->nick;
 }
 
@@ -83,4 +114,10 @@
     my $self = shift;
     return $self->conn->socket;
+}
+
+sub me {
+    my ($self, $to, $msg) = @_;
+    $self->conn->send_msg('privmsg', $to,
+                          encode_ctcp(['ACTION', $msg]))
 }
 
@@ -92,32 +129,50 @@
     my $self = shift;
     my $evt = shift;
-    return BarnOwl::Message->new(
+    my %args = (
         type        => 'IRC',
         server      => $self->server,
         network     => $self->alias,
-        sender      => $evt->nick,
-        hostname    => $evt->host,
-        from        => $evt->from,
         @_
        );
+    if ($evt) {
+        my ($nick, $user, $host) = split_prefix($evt);
+        $args{sender}   ||= $nick;
+        $args{hostname} ||= $host if defined($host);
+        $args{from}     ||= $evt->{prefix};
+        $args{params}   ||= join(' ', @{$evt->{params}})
+    }
+    return BarnOwl::Message->new(%args);
 }
 
 sub on_msg {
-    my ($self, $evt) = @_;
-    my ($recipient) = $evt->to;
-    my $body = strip_irc_formatting([$evt->args]->[0]);
-    my $nick = $self->nick;
-    $body = '* '.$evt->nick.' '.$body if $evt->type eq 'caction';
+    my ($self, $recipient, $evt) = @_;
+    my $body = strip_irc_formatting($evt->{params}->[1]);
+    $self->handle_message($recipient, $evt, $body);
+}
+
+sub on_ctcp_action {
+    my ($self, $src, $target, $msg) = @_;
+    my $body = strip_irc_formatting($msg);
+    my $evt = {
+        params => [$src],
+        type   => 'privmsg',
+        prefix => $src
+       };
+    $self->handle_message($target, $evt, "* $body");
+}
+
+sub handle_message {
+    my ($self, $recipient, $evt, $body) = @_;
     my $msg = $self->new_message($evt,
         direction   => 'in',
         recipient   => $recipient,
-        body => $body,
-        $evt->type eq 'notice' ?
+        body        => $body,
+        ($evt->{command}||'') eq 'notice' ?
           (notice     => 'true') : (),
         is_private($recipient) ?
           (private  => 'true') : (channel => $recipient),
         replycmd    => BarnOwl::quote('irc-msg', '-a', $self->alias,
-          (is_private($recipient) ? $evt->nick : $recipient)),
-        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
+           (is_private($recipient) ? prefix_nick($evt) : $recipient)),
+        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
        );
 
@@ -125,31 +180,27 @@
 }
 
-sub on_ping {
-    my ($self, $evt) = @_;
-    $self->conn->ctcp_reply($evt->nick, join (' ', ($evt->args)));
-}
 
 sub on_admin_msg {
     my ($self, $evt) = @_;
-    return if BarnOwl::Module::IRC->skip_msg($evt->type);
-    BarnOwl::admin_message("IRC",
-            BarnOwl::Style::boldify('IRC ' . $evt->type . ' message from '
+    return if BarnOwl::Module::IRC->skip_msg($evt->{command});
+    BarnOwl::admin_message("IRC",
+            BarnOwl::Style::boldify('IRC ' . $evt->{command} . ' message from '
                 . $self->alias) . "\n"
-            . strip_irc_formatting(join ' ', cdr($evt->args)));
+            . strip_irc_formatting(join ' ', cdr($evt->{params})));
 }
 
 sub on_motdstart {
     my ($self, $evt) = @_;
-    $self->motd(join "\n", cdr($evt->args));
+    $self->motd(join "\n", cdr(@{$evt->{params}}));
 }
 
 sub on_motd {
     my ($self, $evt) = @_;
-    $self->motd(join "\n", $self->motd, cdr($evt->args));
+    $self->motd(join "\n", $self->motd, cdr(@{$evt->{params}}));
 }
 
 sub on_endofmotd {
     my ($self, $evt) = @_;
-    $self->motd(join "\n", $self->motd, cdr($evt->args));
+    $self->motd(join "\n", $self->motd, cdr(@{$evt->{params}}));
     BarnOwl::admin_message("IRC",
             BarnOwl::Style::boldify('MOTD for ' . $self->alias) . "\n"
@@ -159,26 +210,26 @@
 sub on_join {
     my ($self, $evt) = @_;
+    my $chan = $evt->{params}[0];
     my $msg = $self->new_message($evt,
         loginout   => 'login',
         action     => 'join',
-        channel    => $evt->to,
-        replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->to),
-        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
+        channel    => $chan,
+        replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, $chan),
+        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
         );
     BarnOwl::queue_message($msg);
-    push @{$self->channels}, $evt->to;
 }
 
 sub on_part {
     my ($self, $evt) = @_;
+    my $chan = $evt->{params}[0];
     my $msg = $self->new_message($evt,
         loginout   => 'logout',
         action     => 'part',
-        channel    => $evt->to,
-        replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->to),
-        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
+        channel    => $chan,
+        replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, $chan),
+        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
         );
     BarnOwl::queue_message($msg);
-    $self->channels([ grep {$_ ne $evt->to} @{$self->channels}]);
 }
 
@@ -188,8 +239,8 @@
         loginout   => 'logout',
         action     => 'quit',
-        from       => $evt->to,
-        reason     => [$evt->args]->[0],
-        replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
-        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
+        from       => $evt->{prefix},
+        reason     => $evt->{params}->[0],
+        replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
+        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
         );
     BarnOwl::queue_message($msg);
@@ -198,27 +249,24 @@
 sub disconnect {
     my $self = shift;
-    delete $BarnOwl::Module::IRC::ircnets{$self->alias};
-    for my $k (keys %BarnOwl::Module::IRC::channels) {
-        my @conns = grep {$_ ne $self} @{$BarnOwl::Module::IRC::channels{$k}};
-        if(@conns) {
-            $BarnOwl::Module::IRC::channels{$k} = \@conns;
-        } else {
-            delete $BarnOwl::Module::IRC::channels{$k};
-        }
-    }
-    BarnOwl::remove_io_dispatch($self->{FD});
+    $self->conn->disconnect;
+}
+
+sub on_disconnect {
+    my ($self, $why) = @_;
+    BarnOwl::admin_message('IRC',
+                           "[" . $self->alias . "] Disconnected from server: $why");
     $self->motd("");
-}
-
-sub on_disconnect {
-    my ($self, $evt) = @_;
-    $self->disconnect;
-    BarnOwl::admin_message('IRC',
-                           "[" . $self->alias . "] Disconnected from server");
-    if ($evt->format and $evt->format eq "error") {
+    if (!$self->did_quit) {
         $self->schedule_reconnect;
     } else {
-        $self->channels([]);
-    }
+        delete $BarnOwl::Module::IRC::ircnets{$self->alias};
+    }
+}
+
+sub on_error {
+    my ($self, $evt) = @_;
+    BarnOwl::admin_message('IRC',
+                           "[" . $self->alias . "] " .
+                           "Error: " . join(" ", @{$evt->{params}}));
 }
 
@@ -227,17 +275,36 @@
     BarnOwl::admin_message("IRC",
                            "[" . $self->alias . "] " .
-                           [$evt->args]->[1] . ": Nick already in use");
-    $self->disconnect unless $self->motd;
+                           $evt->{params}->[1] . ": Nick already in use");
+}
+
+sub on_nick {
+    my ($self, $old_nick, $new_nick, $is_me) = @_;
+    if ($is_me) {
+        BarnOwl::admin_message("IRC",
+                               "[" . $self->alias . "] " .
+                               "You are now known as $new_nick");
+    } else {
+        my $msg = $self->new_message('',
+            loginout   => 'login',
+            action     => 'nick change',
+            from       => $new_nick,
+            sender     => $new_nick,
+            replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias,
+                                         $new_nick),
+            replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias,
+                                             $new_nick),
+            old_nick   => $old_nick);
+        BarnOwl::queue_message($msg);
+    }
 }
 
 sub on_topic {
-    my ($self, $evt) = @_;
-    my @args = $evt->args;
-    if (scalar @args > 1) {
+    my ($self, $channel, $topic, $who) = @_;
+    if ($channel) {
         BarnOwl::admin_message("IRC",
-                "Topic for $args[1] on " . $self->alias . " is $args[2]");
+                "Topic for $channel on " . $self->alias . " is $topic");
     } else {
         BarnOwl::admin_message("IRC",
-                "Topic changed to $args[0]");
+                "Topic changed to $channel");
     }
 }
@@ -245,5 +312,5 @@
 sub on_topicinfo {
     my ($self, $evt) = @_;
-    my @args = $evt->args;
+    my @args = @{$evt->{params}};
     BarnOwl::admin_message("IRC",
         "Topic for $args[1] set by $args[2] at " . localtime($args[3]));
@@ -257,5 +324,6 @@
     my ($self, $evt) = @_;
     return unless $self->names_tmp;
-    $self->names_tmp([@{$self->names_tmp}, split(' ', [$evt->args]->[3])]);
+    $self->names_tmp([@{$self->names_tmp},
+                      map {prefix_nick($_)} split(' ', $evt->{params}[3])]);
 }
 
@@ -272,5 +340,5 @@
     my ($self, $evt) = @_;
     return unless $self->names_tmp;
-    my $names = BarnOwl::Style::boldify("Members of " . [$evt->args]->[1] . ":\n");
+    my $names = BarnOwl::Style::boldify("Members of " . $evt->{params}->[1] . ":\n");
     for my $name (sort {cmp_user($a, $b)} @{$self->names_tmp}) {
         $names .= "  $name\n";
@@ -282,8 +350,14 @@
 sub on_whois {
     my ($self, $evt) = @_;
+    my %names = (
+        311 => 'user',
+        312 => 'server',
+        319 => 'channels',
+        330 => 'whowas',
+       );
     $self->whois_tmp(
-      $self->whois_tmp . "\n" . $evt->type . ":\n  " .
-      join("\n  ", cdr(cdr($evt->args))) . "\n"
-    );
+        $self->whois_tmp . "\n" . $names{$evt->{command}} . ":\n  " .
+        join("\n  ", cdr(cdr(@{$evt->{params}}))) . "\n"
+       );
 }
 
@@ -291,5 +365,5 @@
     my ($self, $evt) = @_;
     BarnOwl::popless_ztext(
-        BarnOwl::Style::boldify("/whois for " . [$evt->args]->[1] . ":\n") .
+        BarnOwl::Style::boldify("/whois for " . $evt->{params}->[1] . ":\n") .
         $self->whois_tmp
     );
@@ -300,14 +374,15 @@
     my ($self, $evt) = @_;
     BarnOwl::admin_message("IRC",
-                           "[" . $self->alias . "] User " . ($evt->nick) . + " set mode " .
-                           join(" ", $evt->args) . "on " . $evt->to->[0]
+                           "[" . $self->alias . "] User " . (prefix_nick($evt)) . + " set mode " .
+                           join(" ", cdr(@{$evt->{params}})) . " on " . $evt->{params}->[0]
                           );
 }
 
-sub on_nosuchchannel {
-    my ($self, $evt) = @_;
+sub on_nosuch {
+    my ($self, $evt) = @_;
+    my %things = (401 => 'nick', 402 => 'server', 403 => 'channel');
     BarnOwl::admin_message("IRC",
                            "[" . $self->alias . "] " .
-                           "No such channel: " . [$evt->args]->[1])
+                           "No such @{[$things{$evt->{command}}]}: @{[$evt->{params}->[1]]}")
 }
 
@@ -323,7 +398,13 @@
 sub schedule_reconnect {
     my $self = shift;
-    my $interval = shift || 5;
-    delete $BarnOwl::Module::IRC::ircnets{$self->alias};
-    $BarnOwl::Module::IRC::reconnect{$self->alias} = $self;
+    my $interval = $self->backoff;
+    if ($interval) {
+        $interval *= 2;
+        $interval = 60*5 if $interval > 60*5;
+    } else {
+        $interval = 5;
+    }
+    $self->backoff($interval);
+
     my $weak = $self;
     weaken($weak);
@@ -343,9 +424,14 @@
 sub cancel_reconnect {
     my $self = shift;
-    delete $BarnOwl::Module::IRC::reconnect{$self->alias};
+
     if (defined $self->{reconnect_timer}) {
         $self->{reconnect_timer}->stop;
     }
     delete $self->{reconnect_timer};
+}
+
+sub on_connect {
+    my $self = shift;
+    $self->connected("Connected to " . $self->alias . " as " . $self->nick)
 }
 
@@ -355,26 +441,23 @@
     BarnOwl::admin_message("IRC", $msg);
     $self->cancel_reconnect;
-    $BarnOwl::Module::IRC::ircnets{$self->alias} = $self;
-    my $fd = $self->getSocket()->fileno();
-    BarnOwl::add_io_dispatch($fd, 'r', \&BarnOwl::Module::IRC::OwlProcess);
-    $self->{FD} = $fd;
+    if ($self->autoconnect_channels) {
+        for my $c (@{$self->autoconnect_channels}) {
+            $self->conn->send_msg(join => $c);
+        }
+        $self->autoconnect_channels([]);
+    }
+    $self->conn->enable_ping(60, sub {
+                                 $self->on_disconnect("Connection timed out.");
+                                 $self->schedule_reconnect;
+                             });
+    $self->backoff(0);
 }
 
 sub reconnect {
     my $self = shift;
-    my $backoff = shift;
-
-    $self->conn->connect;
-    if ($self->conn->connected) {
-        $self->connected("Reconnected to ".$self->alias);
-        my @channels = @{$self->channels};
-        $self->channels([]);
-        $self->conn->join($_) for @channels;
-        return;
-    }
-
-    $backoff *= 2;
-    $backoff = 60*5 if $backoff > 60*5;
-    $self->schedule_reconnect( $backoff );
+    my $backoff = $self->backoff;
+
+    $self->autoconnect_channels([keys(%{$self->{channel_list}})]);
+    $self->conn->connect(@{$self->connect_args});
 }
 
Index: perlconfig.c
===================================================================
--- perlconfig.c	(revision f25df21f6284aedd48c098bc68cee9896da5ce98)
+++ perlconfig.c	(revision 3b8a563ae4e07b1064fe005714793565ac720dc4)
@@ -403,4 +403,6 @@
   }
 
+  sv_setpv(get_sv("BarnOwl::VERSION", TRUE), OWL_VERSION_STRING);
+
   /* Add the system lib path to @INC */
   inc = get_av("INC", 0);
@@ -465,5 +467,5 @@
                                            :"BarnOwl::_receive_msg_legacy_wrap", m);
   }
-  if (ptr) g_free(ptr);
+  g_free(ptr);
 }
 
@@ -476,5 +478,5 @@
                                            :"BarnOwl::Hooks::_new_msg", m);
   }
-  if (ptr) g_free(ptr);
+  g_free(ptr);
 }
 
Index: perlglue.xs
===================================================================
--- perlglue.xs	(revision f25df21f6284aedd48c098bc68cee9896da5ce98)
+++ perlglue.xs	(revision 3b8a563ae4e07b1064fe005714793565ac720dc4)
@@ -43,5 +43,6 @@
 			rv = owl_function_command(cmd);
 		} else {
-			argv = g_new(const char *, items + 1);
+			/* Ensure this is NULL-terminated. */
+			argv = g_new0(const char *, items + 1);
 			argv[0] = cmd;
 			for(i = 1; i < items; i++) {
@@ -56,5 +57,5 @@
 		RETVAL
 	CLEANUP:
-		if (rv) g_free(rv);
+		g_free(rv);
 
 SV *
@@ -113,5 +114,5 @@
 		RETVAL
 	CLEANUP:
-		if (rv) g_free(rv);
+		g_free(rv);
 
 const utf8 *
@@ -140,5 +141,5 @@
 		RETVAL
     CLEANUP:
-		if (rv) g_free(rv);
+		g_free(rv);
 
 void
@@ -323,6 +324,5 @@
 		RETVAL
 	CLEANUP:
-		if (rv)
-			g_free(rv);
+		g_free(rv);
 
 void
Index: select.c
===================================================================
--- select.c	(revision ba12b446949c02a6b7649d518b91def2056e2cbb)
+++ select.c	(revision ba12b446949c02a6b7649d518b91def2056e2cbb)
@@ -321,4 +321,24 @@
 }
 
+#if 0
+/* FIXME: Reimplement this check in the glib world. */
+static void owl_select_prune_bad_fds(void) {
+  owl_list *dl = owl_global_get_io_dispatch_list(&g);
+  int len, i;
+  struct stat st;
+  owl_io_dispatch *d;
+
+  len = owl_list_get_size(dl);
+  for (i = 0; i < len; i++) {
+    d = owl_list_get_element(dl, i);
+    if (fstat(d->fd, &st) < 0 && errno == EBADF) {
+      owl_function_debugmsg("Pruning defunct dispatch on fd %d.", d->fd);
+      d->needs_gc = 1;
+    }
+  }
+  owl_select_io_dispatch_gc();
+}
+#endif
+
 typedef struct _owl_task { /*noproto*/
   void (*cb)(void *);
Index: tester.c
===================================================================
--- tester.c	(revision f25df21f6284aedd48c098bc68cee9896da5ce98)
+++ tester.c	(revision 4c7c21f786a0416a755645b78db0b851f75f8748)
@@ -233,5 +233,5 @@
 
   printf("# BEGIN testing owl_dict\n");
-  FAIL_UNLESS("create", 0==owl_dict_create(&d));
+  owl_dict_create(&d);
   FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_delete));
   FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_delete));
@@ -249,5 +249,5 @@
   FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d));
   owl_list_create(&l);
-  FAIL_UNLESS("get_keys", 0==owl_dict_get_keys(&d, &l));
+  owl_dict_get_keys(&d, &l);
   FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l));
   
Index: text.c
===================================================================
--- text.c	(revision 42ee1befb24d0ac6b39443512cd22be47a782563)
+++ text.c	(revision 7865479440dd042766ecbbc1119b45e5eb7cd6a6)
@@ -275,18 +275,4 @@
   g_strfreev(split);
   return out;
-}
-
-/* replace all instances of character a in buff with the character
- * b.  buff must be null terminated.
- */
-void owl_text_tr(char *buff, char a, char b)
-{
-  int i;
-
-  owl_function_debugmsg("In: %s", buff);
-  for (i=0; buff[i]!='\0'; i++) {
-    if (buff[i]==a) buff[i]=b;
-  }
-  owl_function_debugmsg("Out: %s", buff);
 }
 
Index: util.c
===================================================================
--- util.c	(revision e56303f7b60f05cc30e74453b06725fc031e9384)
+++ util.c	(revision 9efa5bd38b986cf116a08ae43aa3f8629dcc6e60)
@@ -715,4 +715,15 @@
 }
 
+int owl_util_get_colorpairs(void) {
+#ifndef NCURSES_EXT_COLORS
+  /* Without ext-color support (an ABI change), ncurses only supports 256
+   * different color pairs. However, it gives us a larger number even if your
+   * ncurses is compiled without ext-color. */
+  return MIN(COLOR_PAIRS, 256);
+#else
+  return COLOR_PAIRS;
+#endif
+}
+
 gulong owl_dirty_window_on_signal(owl_window *w, gpointer sender, const gchar *detailed_signal)
 {
Index: variable.c
===================================================================
--- variable.c	(revision f25df21f6284aedd48c098bc68cee9896da5ce98)
+++ variable.c	(revision 4c7c21f786a0416a755645b78db0b851f75f8748)
@@ -30,6 +30,6 @@
         NULL, NULL, NULL, NULL, NULL, NULL }
 
-#define OWLVAR_STRING_FULL(name,default,summary,description,validate,set,get) \
-        { name, OWL_VARIABLE_STRING, default, 0, "<string>", summary,description, NULL, \
+#define OWLVAR_STRING_FULL(name,default,validset,summary,description,validate,set,get) \
+        { name, OWL_VARIABLE_STRING, default, 0, validset, summary,description, NULL, \
         validate, set, NULL, get, NULL, NULL }
 
@@ -266,5 +266,5 @@
 		 "" ),
 
-  OWLVAR_STRING_FULL( "tty" /* %OwlVarStub */, "", "tty name for zephyr location", "",
+  OWLVAR_STRING_FULL( "tty" /* %OwlVarStub */, "", "<string>", "tty name for zephyr location", "",
 		      NULL, owl_variable_tty_set, NULL),
 
@@ -370,4 +370,69 @@
 	       "delete a message right as it came in.\n" ),
 
+  OWLVAR_STRING_FULL( "default_exposure" /* %OwlVarStub */, "",
+                      "none,opstaff,realm-visible,realm-announced,net-visible,net-announced",
+                      "controls the persistent value for exposure",
+                      "The default exposure level corresponds to the Zephyr exposure value\n"
+                      "in ~/.zephyr.vars.  Defaults to realm-visible if there is no value in\n"
+                      "~/.zephyr.vars.\n"
+                      "See the description of exposure for the values this can be.",
+                      NULL, owl_variable_default_exposure_set, owl_variable_default_exposure_get ),
+
+  OWLVAR_STRING_FULL( "exposure" /* %OwlVarStub */, "",
+                      "none,opstaff,realm-visible,realm-announced,net-visible,net-announced",
+                      "controls who can zlocate you",
+                      "The exposure level, defaulting to the value of default_exposure,\n"
+                      "can be one of the following (from least exposure to widest exposure,\n"
+                      "as listed in zctl(1)):\n"
+                      "\n"
+                      "   none            - This completely disables Zephyr for the user. \n"
+                      "                     The user is not registered with Zephyr.  No user\n"
+                      "                     location information is retained by Zephyr.  No\n"
+                      "                     login or logout announcements will be sent.  No\n"
+                      "                     subscriptions will be entered for the user, and\n"
+                      "                     no notices will be displayed by zwgc(1).\n"
+                      "   opstaff         - The user is registered with Zephyr.  No login or\n"
+                      "                     logout announcements will be sent, and location\n"
+                      "                     information will only be visible to Operations\n"
+                      "                     staff.  Default subscriptions and any additional\n"
+                      "                     personal subscriptions will be entered for the\n"
+                      "                     user.\n"
+                      "   realm-visible   - The user is registered with Zephyr.  User\n"
+                      "                     location information is retained by Zephyr and\n"
+                      "                     made available only to users within the user’s\n"
+                      "                     Kerberos realm.  No login or logout\n"
+                      "                     announcements will be sent.  This is the system\n"
+                      "                     default.  Default subscriptions and any\n"
+                      "                     additional personal subscriptions will be\n"
+                      "                     entered for the user.\n"
+                      "   realm-announced - The user is registered with Zephyr.  User\n"
+                      "                     location information is retained by Zephyr and\n"
+                      "                     made available only to users authenticated\n"
+                      "                     within the user’s Kerberos realm.  Login and\n"
+                      "                     logout announcements will be sent, but only to\n"
+                      "                     users within the user’s Kerberos realm who have\n"
+                      "                     explicitly requested such via subscriptions. \n"
+                      "                     Default subscriptions and any additional\n"
+                      "                     personal subscriptions will be entered for the\n"
+                      "                     user.\n"
+                      "   net-visible     - The user is registered with Zephyr.  User\n"
+                      "                     location information is retained by Zephyr and\n"
+                      "                     made available to any authenticated user who\n"
+                      "                     requests such.  Login and logout announcements\n"
+                      "                     will be sent only to users within the user’s\n"
+                      "                     Kerberos realm who have explicitly requested\n"
+                      "                     such via subscriptions.  Default subscriptions\n"
+                      "                     and any additional personal subscriptions will\n"
+                      "                     be entered for the user.\n"
+                      "   net-announced   - The user is registered with Zephyr.  User\n"
+                      "                     location information is retained by Zephyr and\n"
+                      "                     made available to any authenticated user who\n"
+                      "                     requests such.  Login and logout announcements\n"
+                      "                     will be sent to any user has requested such. \n"
+                      "                     Default subscriptions and any additional\n"
+                      "                     personal subscriptions will be entered for the\n"
+                      "                     user.\n",
+                      NULL, owl_variable_exposure_set, NULL /* use default for get */ ),
+
   /* This MUST be last... */
   { NULL, 0, NULL, 0, NULL, NULL, NULL, NULL,
@@ -470,4 +535,21 @@
 }
 
+int owl_variable_default_exposure_set(owl_variable *v, const void *newval)
+{
+  return owl_zephyr_set_default_exposure(newval);
+}
+
+const void *owl_variable_default_exposure_get(const owl_variable *v)
+{
+  return owl_zephyr_get_default_exposure();
+}
+
+int owl_variable_exposure_set(owl_variable *v, const void *newval)
+{
+  int ret = owl_zephyr_set_exposure(newval);
+  if (ret != 0)
+    return ret;
+  return owl_variable_string_set_default(v, owl_zephyr_normalize_exposure(newval));
+}
 
 /**************************************************************************/
@@ -477,5 +559,5 @@
 int owl_variable_dict_setup(owl_vardict *vd) {
   owl_variable *var, *cur;
-  if (owl_dict_create(vd)) return(-1);
+  owl_dict_create(vd);
   for (var = variables_to_init; var->name != NULL; var++) {
     cur = g_new(owl_variable, 1);
@@ -559,7 +641,7 @@
 
 void owl_variable_update(owl_variable *var, const char *summary, const char *desc) {
-  if(var->summary) g_free(var->summary);
+  g_free(var->summary);
   var->summary = g_strdup(summary);
-  if(var->description) g_free(var->description);
+  g_free(var->description);
   var->description = g_strdup(desc);
 }
@@ -569,5 +651,5 @@
   if(old) {
     owl_variable_update(old, summ, desc);
-    if(old->pval_default) g_free(old->pval_default);
+    g_free(old->pval_default);
     old->pval_default = g_strdup(initval);
   } else {
@@ -688,5 +770,5 @@
   }
   if (msg && v->get_tostring_fn) {
-    tostring = v->get_tostring_fn(v, v->val);
+    tostring = v->get_tostring_fn(v, v->get_fn(v));
     owl_function_makemsg("%s = '%s'", name, tostring);
     g_free(tostring);
@@ -726,5 +808,5 @@
   v = owl_dict_find_element(d, name);
   if (v == NULL || !v->get_tostring_fn) return NULL;
-  return v->get_tostring_fn(v, v->val);
+  return v->get_tostring_fn(v, v->get_fn(v));
 }
 
@@ -862,5 +944,5 @@
 void owl_variable_delete_default(owl_variable *v)
 {
-  if (v->val) g_free(v->val);
+  g_free(v->val);
 }
 
@@ -994,5 +1076,5 @@
     if (!v->validate_fn(v, newval)) return(-1);
   }
-  if (v->val) g_free(v->val);
+  g_free(v->val);
   v->val = g_strdup(newval);
   return(0);
Index: view.c
===================================================================
--- view.c	(revision d4927a70549407fe7f56b4ae1d3949663a370205)
+++ view.c	(revision 3b8a563ae4e07b1064fe005714793565ac720dc4)
@@ -160,4 +160,4 @@
 {
   owl_list_cleanup(&v->ml.list, NULL);
-  if (v->name) g_free(v->name);
+  g_free(v->name);
 }
Index: viewwin.c
===================================================================
--- viewwin.c	(revision 237d02c0b7dc9e5a2f942f7dbcad63b75830350b)
+++ viewwin.c	(revision 4fd211f3a533efcedaf4d0dc7c01e02087ad2e39)
@@ -150,5 +150,5 @@
 
   if (!owl_viewwin_search(v, owl_global_get_search_re(&g), consider_current, direction))
-    owl_function_error("No more matches");
+    owl_function_makemsg("No more matches");
   return NULL;
 }
@@ -172,5 +172,5 @@
   if (!owl_viewwin_search(data->v, owl_global_get_search_re(&g),
                           consider_current, data->direction))
-    owl_function_error("No matches");
+    owl_function_makemsg("No matches");
 }
 
Index: window.c
===================================================================
--- window.c	(revision 4cc49bce5bdc20cd8da2b4e305f60d04ae879d4f)
+++ window.c	(revision 4cc49bce5bdc20cd8da2b4e305f60d04ae879d4f)
@@ -547,11 +547,12 @@
   /* update the terminal if we need to */
   owl_window_redraw_scheduled();
-  /* On colorpair shortage, reset and redraw /everything/. NOTE: if
-   * the current screen uses too many colorpairs, this draws
-   * everything twice. But this is unlikely; COLOR_PAIRS is 64 with
-   * 8+1 colors, and 256^2 with 256+1 colors. (+1 for default.) */
+  /* On colorpair shortage, reset and redraw /everything/. NOTE: if we
+   * still overflow, this be useless work. With 8-colors, we get 64
+   * pairs. With 256-colors, we get 32768 pairs with ext-colors
+   * support and 256 otherwise. */
   cpmgr = owl_global_get_colorpair_mgr(&g);
   if (cpmgr->overflow) {
-    owl_function_debugmsg("colorpairs: color shortage; reset pairs and redraw. COLOR_PAIRS = %d", COLOR_PAIRS);
+    owl_function_debugmsg("colorpairs: used all %d pairs; reset pairs and redraw.",
+                          owl_util_get_colorpairs());
     owl_fmtext_reset_colorpairs(cpmgr);
     owl_function_full_redisplay();
Index: zcrypt.c
===================================================================
--- zcrypt.c	(revision 1dd285b0045528991a838942c7ba925dbcf64128)
+++ zcrypt.c	(revision 3b8a563ae4e07b1064fe005714793565ac720dc4)
@@ -476,12 +476,8 @@
 
   for(i = 0; i < MAX_SEARCH; i++) {
-    if(varname[i] != NULL) {
-      g_free(varname[i]);
-    }
-  }
-
-  if(filename != NULL) {
-    g_free(filename);
-  }
+    g_free(varname[i]);
+  }
+
+  g_free(filename);
 
   return keyfile;
@@ -773,5 +769,5 @@
   err = call_filter("gpg", argv, in, &out, &status);
   if(err || status) {
-    if(out) g_free(out);
+    g_free(out);
     return FALSE;
   }
@@ -856,5 +852,5 @@
   err = call_filter("gpg", argv, in, &out, &status);
   if(err || status) {
-    if(out) g_free(out);
+    g_free(out);
     return FALSE;
   }
Index: zephyr.c
===================================================================
--- zephyr.c	(revision 959cb85c4c02b9474fc3ece82a6ebc7f47ee2cf3)
+++ zephyr.c	(revision 959cb85c4c02b9474fc3ece82a6ebc7f47ee2cf3)
@@ -447,6 +447,5 @@
     return 0;
   }
-  if (buffer)
-    g_free(buffer);
+  g_free(buffer);
 
   return owl_zephyr_loadsubs_helper(subs, count);
@@ -1049,19 +1048,8 @@
 {
 #ifdef HAVE_LIBZEPHYR
-  char *exposure, *eset;
-  Code_t ret;
-
   ZResetAuthentication();
 
-  eset = EXPOSE_REALMVIS;
-  exposure = ZGetVariable(zstr("exposure"));
-  if (exposure)
-    exposure = ZParseExposureLevel(exposure);
-  if (exposure)
-    eset = exposure;
-   
-  ret = ZSetLocation(eset);
-  if (ret != ZERR_NONE)
-    owl_function_error("Error setting location: %s", error_message(ret));
+  /* ZSetLocation, and store the default value as the current value */
+  owl_global_set_exposure(&g, owl_global_get_default_exposure(&g));
 #endif
 }
@@ -1184,4 +1172,66 @@
   ZInitLocationInfo(zstr(host), zstr(val));
 #endif
+}
+
+const char *owl_zephyr_normalize_exposure(const char *exposure)
+{
+  if (exposure == NULL)
+    return NULL;
+#ifdef HAVE_LIBZEPHYR
+  return ZParseExposureLevel(zstr(exposure));
+#else
+  return exposure;
+#endif
+}
+
+int owl_zephyr_set_default_exposure(const char *exposure)
+{
+#ifdef HAVE_LIBZEPHYR
+  Code_t ret;
+  if (exposure == NULL)
+    return -1;
+  exposure = ZParseExposureLevel(zstr(exposure));
+  if (exposure == NULL)
+    return -1;
+  ret = ZSetVariable(zstr("exposure"), zstr(exposure)); /* ZSetVariable does file I/O */
+  if (ret != ZERR_NONE) {
+    owl_function_error("Unable to set default exposure location: %s", error_message(ret));
+    return -1;
+  }
+#endif
+  return 0;
+}
+
+const char *owl_zephyr_get_default_exposure(void)
+{
+#ifdef HAVE_LIBZEPHYR
+  const char *exposure = ZGetVariable(zstr("exposure")); /* ZGetVariable does file I/O */
+  if (exposure == NULL)
+    return EXPOSE_REALMVIS;
+  exposure = ZParseExposureLevel(zstr(exposure));
+  if (exposure == NULL) /* The user manually entered an invalid value in ~/.zephyr.vars, or something weird happened. */
+    return EXPOSE_REALMVIS;
+  return exposure;
+#else
+  return "";
+#endif
+}
+
+int owl_zephyr_set_exposure(const char *exposure)
+{
+#ifdef HAVE_LIBZEPHYR
+  Code_t ret;
+  if (exposure == NULL)
+    return -1;
+  exposure = ZParseExposureLevel(zstr(exposure));
+  if (exposure == NULL)
+    return -1;
+  ret = ZSetLocation(zstr(exposure));
+  if (ret != ZERR_NONE) {
+    owl_function_error("Unable to set exposure level: %s.", error_message(ret));
+    return -1;
+  }
+#endif
+  return 0;
 }
   
Index: zwrite.c
===================================================================
--- zwrite.c	(revision 3f52e1446b6b705636f09d02d657c28d38ef29a2)
+++ zwrite.c	(revision 3b8a563ae4e07b1064fe005714793565ac720dc4)
@@ -185,5 +185,5 @@
 void owl_zwrite_set_message_raw(owl_zwrite *z, const char *msg)
 {
-  if (z->message) g_free(z->message);
+  g_free(z->message);
   z->message = owl_validate_utf8(msg);
 }
@@ -195,5 +195,5 @@
   char *tmp = NULL, *tmp2;
 
-  if (z->message) g_free(z->message);
+  g_free(z->message);
 
   j=owl_list_get_size(&(z->recips));
@@ -289,5 +289,5 @@
 void owl_zwrite_set_opcode(owl_zwrite *z, const char *opcode)
 {
-  if (z->opcode) g_free(z->opcode);
+  g_free(z->opcode);
   z->opcode=owl_validate_utf8(opcode);
 }
@@ -306,5 +306,5 @@
 void owl_zwrite_set_zsig(owl_zwrite *z, const char *zsig)
 {
-  if(z->zsig) g_free(z->zsig);
+  g_free(z->zsig);
   z->zsig = g_strdup(zsig);
 }
@@ -353,12 +353,12 @@
 {
   owl_list_cleanup(&(z->recips), &g_free);
-  if (z->cmd) g_free(z->cmd);
-  if (z->zwriteline) g_free(z->zwriteline);
-  if (z->class) g_free(z->class);
-  if (z->inst) g_free(z->inst);
-  if (z->opcode) g_free(z->opcode);
-  if (z->realm) g_free(z->realm);
-  if (z->message) g_free(z->message);
-  if (z->zsig) g_free(z->zsig);
+  g_free(z->cmd);
+  g_free(z->zwriteline);
+  g_free(z->class);
+  g_free(z->inst);
+  g_free(z->opcode);
+  g_free(z->realm);
+  g_free(z->message);
+  g_free(z->zsig);
 }
 
