--- a/cmd-rename-session.c
+++ b/cmd-rename-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-rename-session.c,v 1.20 2010-08-11 22:19:03 tcunha Exp $ */
+/* $Id: cmd-rename-session.c,v 1.21 2010-12-22 15:36:44 tcunha Exp $ */
 
 /*
  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -53,8 +53,10 @@
 	if ((s = cmd_find_session(ctx, data->target)) == NULL)
 		return (-1);
 
+	RB_REMOVE(sessions, &sessions, s);
 	xfree(s->name);
 	s->name = xstrdup(data->arg);
+	RB_INSERT(sessions, &sessions, s);
 
 	server_status_session(s);