Index: bitlbee.c
===================================================================
--- bitlbee.c	(revision 5898ef8b07375b71637f585d07fc451e5910c6bf)
+++ bitlbee.c	(revision c121f8945f7249520342ad86ff00f4986642ca0a)
@@ -228,5 +228,5 @@
 		irc->w_watch_source_id = 0;
 		
-		if( irc->status & USTATUS_SHUTDOWN )
+		if( irc->status == USTATUS_SHUTDOWN )
 			irc_free( irc );
 		
Index: ipc.c
===================================================================
--- ipc.c	(revision 5898ef8b07375b71637f585d07fc451e5910c6bf)
+++ ipc.c	(revision c121f8945f7249520342ad86ff00f4986642ca0a)
@@ -115,5 +115,5 @@
 static void ipc_child_cmd_wallops( irc_t *irc, char **cmd )
 {
-	if( !( irc->status & USTATUS_LOGGED_IN ) )
+	if( irc->status < USTATUS_LOGGED_IN )
 		return;
 	
@@ -124,5 +124,5 @@
 static void ipc_child_cmd_lilo( irc_t *irc, char **cmd )
 {
-	if( !( irc->status & USTATUS_LOGGED_IN ) )
+	if( irc->status < USTATUS_LOGGED_IN )
 		return;
 	
@@ -133,5 +133,5 @@
 static void ipc_child_cmd_opermsg( irc_t *irc, char **cmd )
 {
-	if( !( irc->status & USTATUS_LOGGED_IN ) )
+	if( irc->status < USTATUS_LOGGED_IN )
 		return;
 	
@@ -154,5 +154,5 @@
 static void ipc_child_cmd_kill( irc_t *irc, char **cmd )
 {
-	if( !( irc->status & USTATUS_LOGGED_IN ) )
+	if( irc->status < USTATUS_LOGGED_IN )
 		return;
 	
@@ -166,5 +166,5 @@
 static void ipc_child_cmd_hello( irc_t *irc, char **cmd )
 {
-	if( !( irc->status & USTATUS_LOGGED_IN ) )
+	if( irc->status < USTATUS_LOGGED_IN )
 		ipc_to_master_str( "HELLO\r\n" );
 	else
Index: irc.c
===================================================================
--- irc.c	(revision 5898ef8b07375b71637f585d07fc451e5910c6bf)
+++ irc.c	(revision c121f8945f7249520342ad86ff00f4986642ca0a)
@@ -177,5 +177,5 @@
 	}
 	
-	irc->status |= USTATUS_SHUTDOWN;
+	irc->status = USTATUS_SHUTDOWN;
 	if( irc->sendbuffer && !immed )
 	{
@@ -211,5 +211,5 @@
 	log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd );
 	
-	if( irc->status & USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) ) 
+	if( irc->status >= USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) ) 
 		if( storage_save( irc, TRUE ) != STORAGE_OK )
 			irc_usermsg( irc, "Error while saving settings!" );
@@ -577,5 +577,5 @@
 		
 	/* Don't try to write anything new anymore when shutting down. */
-	if( irc->status & USTATUS_SHUTDOWN )
+	if( irc->status == USTATUS_SHUTDOWN )
 		return;
 	
@@ -707,5 +707,5 @@
 	if( irc->user && irc->nick )
 	{
-		if( global.conf->authmode == AUTHMODE_CLOSED && !( irc->status & USTATUS_AUTHORIZED ) )
+		if( global.conf->authmode == AUTHMODE_CLOSED && irc->status < USTATUS_AUTHORIZED )
 		{
 			irc_reply( irc, 464, ":This server is password-protected." );
@@ -764,5 +764,5 @@
 		ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->host, irc->nick, irc->realname );
 	
-	irc->status |= USTATUS_LOGGED_IN;
+	irc->status = USTATUS_LOGGED_IN;
 }
 
@@ -1187,5 +1187,5 @@
 	int rv = 0;
 	
-	if( !( irc->status & USTATUS_LOGGED_IN ) )
+	if( irc->status < USTATUS_LOGGED_IN )
 	{
 		if( gettime() > ( irc->last_pong + IRC_LOGIN_TIMEOUT ) )
Index: irc.h
===================================================================
--- irc.h	(revision 5898ef8b07375b71637f585d07fc451e5910c6bf)
+++ irc.h	(revision c121f8945f7249520342ad86ff00f4986642ca0a)
@@ -42,8 +42,8 @@
 {
 	USTATUS_OFFLINE = 0,
-	USTATUS_AUTHORIZED = 1,
-	USTATUS_LOGGED_IN = 2,
-	USTATUS_IDENTIFIED = 4,
-	USTATUS_SHUTDOWN = 8
+	USTATUS_AUTHORIZED,
+	USTATUS_LOGGED_IN,
+	USTATUS_IDENTIFIED,
+	USTATUS_SHUTDOWN = -1
 } irc_status_t;
 
Index: irc_commands.c
===================================================================
--- irc_commands.c	(revision 5898ef8b07375b71637f585d07fc451e5910c6bf)
+++ irc_commands.c	(revision c121f8945f7249520342ad86ff00f4986642ca0a)
@@ -32,5 +32,5 @@
 	if( global.conf->auth_pass && strcmp( cmd[1], global.conf->auth_pass ) == 0 )
 	{
-		irc->status |= USTATUS_AUTHORIZED;
+		irc->status = USTATUS_AUTHORIZED;
 		irc_check_login( irc );
 	}
@@ -610,9 +610,9 @@
 			for( n_arg = 0; cmd[n_arg]; n_arg ++ ); n_arg --;
 			
-			if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN )
+			if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status >= USTATUS_LOGGED_IN )
 			{
 				irc_reply( irc, 462, ":Only allowed before logging in" );
 			}
-			else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) )
+			else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && irc->status < USTATUS_LOGGED_IN )
 			{
 				irc_reply( irc, 451, ":Register first" );
Index: protocols/msn/msn.c
===================================================================
--- protocols/msn/msn.c	(revision 5898ef8b07375b71637f585d07fc451e5910c6bf)
+++ protocols/msn/msn.c	(revision c121f8945f7249520342ad86ff00f4986642ca0a)
@@ -64,36 +64,31 @@
 	GSList *l;
 	
-	if( md )
-	{
-		if( md->fd >= 0 )
-			closesocket( md->fd );
-		
-		if( md->handler )
-		{
-			if( md->handler->rxq ) g_free( md->handler->rxq );
-			if( md->handler->cmd_text ) g_free( md->handler->cmd_text );
-			g_free( md->handler );
-		}
-		
-		while( md->switchboards )
-			msn_sb_destroy( md->switchboards->data );
-		
-		if( md->msgq )
-		{
-			struct msn_message *m;
-			
-			for( l = md->msgq; l; l = l->next )
-			{
-				m = l->data;
-			
-				serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who );
-				g_free( m->who );
-				g_free( m->text );
-				g_free( m );
-			}
-			g_slist_free( md->msgq );
-		}
-		
-		g_free( md );
+	if( md->fd >= 0 )
+		closesocket( md->fd );
+	
+	if( md->handler )
+	{
+		if( md->handler->rxq ) g_free( md->handler->rxq );
+		if( md->handler->cmd_text ) g_free( md->handler->cmd_text );
+		g_free( md->handler );
+	}
+	
+	while( md->switchboards )
+		msn_sb_destroy( md->switchboards->data );
+	
+	if( md->msgq )
+	{
+		struct msn_message *m;
+		
+		for( l = md->msgq; l; l = l->next )
+		{
+			m = l->data;
+		
+			serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who );
+			g_free( m->who );
+			g_free( m->text );
+			g_free( m );
+		}
+		g_slist_free( md->msgq );
 	}
 	
@@ -105,4 +100,6 @@
 		g_free( l->data );
 	g_slist_free( gc->deny );
+	
+	g_free( md );
 	
 	msn_connections = g_slist_remove( msn_connections, gc );
Index: root_commands.c
===================================================================
--- root_commands.c	(revision 5898ef8b07375b71637f585d07fc451e5910c6bf)
+++ root_commands.c	(revision c121f8945f7249520342ad86ff00f4986642ca0a)
@@ -164,5 +164,5 @@
 			
 		case STORAGE_OK:
-			irc->status |= USTATUS_IDENTIFIED;
+			irc->status = USTATUS_IDENTIFIED;
 			irc_umode_set( irc, "+R", 1 );
 			break;
@@ -188,5 +188,5 @@
 	case STORAGE_OK:
 		irc_setpass( irc, NULL );
-		irc->status &= ~USTATUS_IDENTIFIED;
+		irc->status = USTATUS_LOGGED_IN;
 		irc_umode_set( irc, "-R", 1 );
 		irc_usermsg( irc, "Account `%s' removed", irc->nick );
@@ -202,5 +202,5 @@
 	account_t *a;
 	
-	if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) )
+	if( global.conf->authmode == AUTHMODE_REGISTERED && irc->status < USTATUS_IDENTIFIED )
 	{
 		irc_usermsg( irc, "This server only accepts registered users" );
Index: storage_text.c
===================================================================
--- storage_text.c	(revision 5898ef8b07375b71637f585d07fc451e5910c6bf)
+++ storage_text.c	(revision c121f8945f7249520342ad86ff00f4986642ca0a)
@@ -71,5 +71,5 @@
 	user_t *ru = user_find( irc, ROOT_NICK );
 	
-	if( irc->status & USTATUS_IDENTIFIED )
+	if( irc->status >= USTATUS_IDENTIFIED )
 		return( 1 );
 	
@@ -88,5 +88,5 @@
 	/* Do this now. If the user runs with AuthMode = Registered, the
 	   account command will not work otherwise. */
-	irc->status |= USTATUS_IDENTIFIED;
+	irc->status = USTATUS_IDENTIFIED;
 	
 	while( fscanf( fp, "%511[^\n]s", s ) > 0 )
Index: storage_xml.c
===================================================================
--- storage_xml.c	(revision 5898ef8b07375b71637f585d07fc451e5910c6bf)
+++ storage_xml.c	(revision c121f8945f7249520342ad86ff00f4986642ca0a)
@@ -169,16 +169,4 @@
 static void xml_end_element( GMarkupParseContext *ctx, const gchar *element_name, gpointer data, GError **error )
 {
-	struct xml_parsedata *xd = data;
-	// irc_t *irc = xd->irc;
-	
-	if( g_strcasecmp( element_name, "setting" ) == 0 && xd->current_setting )
-	{
-		g_free( xd->current_setting );
-		xd->current_setting = NULL;
-	}
-	else if( g_strcasecmp( element_name, "account" ) == 0 )
-	{
-		xd->current_account = NULL;
-	}
 }
 
@@ -200,4 +188,8 @@
 		xd->current_setting = NULL;
 	}
+}
+
+static void xml_error( GMarkupParseContext *ctx, GError *error, gpointer data )
+{
 }
 
@@ -208,5 +200,5 @@
 	xml_text,
 	NULL,
-	NULL
+	xml_error
 };
 
@@ -227,5 +219,5 @@
 	int fd, st;
 	
-	if( irc->status & USTATUS_IDENTIFIED )
+	if( irc->status >= USTATUS_IDENTIFIED )
 		return( 1 );
 	
@@ -252,23 +244,17 @@
 		{
 			g_markup_parse_context_free( ctx );
-			close( fd );
-			
-			/* Slightly dirty... */
+			
+			/* TODO: Display useful error msg */
+			
 			if( gerr && strcmp( gerr->message, XML_PASS_ERRORMSG ) == 0 )
 				return STORAGE_INVALID_PASSWORD;
 			else
-			{
-				if( gerr )
-					irc_usermsg( irc, "Error from XML-parser: %s", gerr->message );
-				
 				return STORAGE_OTHER_ERROR;
-			}
 		}
 	}
 	
 	g_markup_parse_context_free( ctx );
-	close( fd );
-	
-	irc->status |= USTATUS_IDENTIFIED;
+	
+	irc->status = USTATUS_IDENTIFIED;
 	
 	if( set_getint( irc, "auto_connect" ) )
@@ -282,92 +268,17 @@
 }
 
-static int xml_printf( int fd, char *fmt, ... )
-{
-	va_list params;
-	char *out;
-	int len;
-	
-	va_start( params, fmt );
-	out = g_markup_vprintf_escaped( fmt, params );
-	va_end( params );
-	
-	len = strlen( out );
-	len -= write( fd, out, len );
-	g_free( out );
-	
-	return len == 0;
-}
-
 static storage_status_t xml_save( irc_t *irc, int overwrite )
 {
-	char path[512], *path2;
-	set_t *set;
-	nick_t *nick;
-	account_t *acc;
-	int fd;
-	
-	g_snprintf( path, sizeof( path ) - 2, "%s%s%s", global.conf->configdir, irc->nick, ".xml" );
-	
-	if( !overwrite && access( path, F_OK ) != -1 )
-		return STORAGE_ALREADY_EXISTS;
-	
-	strcat( path, "~" );
-	if( ( fd = open( path, O_WRONLY | O_CREAT, 0600 ) ) < 0 )
-	{
-		irc_usermsg( irc, "Error while opening configuration file." );
-		return STORAGE_OTHER_ERROR;
-	}
-	
-	if( !xml_printf( fd, "<user nick=\"%s\" password=\"%s\">\n", irc->nick, irc->password ) )
-		goto write_error;
-	
-	for( set = irc->set; set; set = set->next )
-		if( set->value && set->def )
-			if( !xml_printf( fd, "\t<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
-				goto write_error;
-	
-	for( acc = irc->accounts; acc; acc = acc->next )
-	{
-		if( !xml_printf( fd, "\t<account protocol=\"%s\" handle=\"%s\" password=\"%s\" autoconnect=\"%s\"", acc->prpl->name, acc->user, acc->pass, "yes" ) )
-			goto write_error;
-		if( acc->server && acc->server[0] && !xml_printf( fd, " server=\"%s\"", acc->server ) )
-			goto write_error;
-		if( !xml_printf( fd, ">\n" ) )
-			goto write_error;
-		
-		for( nick = irc->nicks; nick; nick = nick->next )
-			if( nick->proto == acc->prpl )
-				if( !xml_printf( fd, "\t\t<buddy handle=\"%s\" nick=\"%s\" />\n", nick->handle, nick->nick ) )
-					goto write_error;
-		
-		if( !xml_printf( fd, "\t</account>\n" ) )
-			goto write_error;
-	}
-	
-	if( !xml_printf( fd, "</user>\n" ) )
-		goto write_error;
-	
-	close( fd );
-	
-	path2 = g_strndup( path, strlen( path ) - 1 );
-	if( rename( path, path2 ) != 0 )
-	{
-		irc_usermsg( irc, "Error while renaming temporary configuration file." );
-		
-		g_free( path2 );
-		unlink( path );
-		
-		return STORAGE_OTHER_ERROR;
-	}
-	
-	g_free( path2 );
-	
+/*	if (!overwrite) {
+		g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
+		if (access( path, F_OK ) != -1)
+			return STORAGE_ALREADY_EXISTS;
+	
+		g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
+		if (access( path, F_OK ) != -1)
+			return STORAGE_ALREADY_EXISTS;
+	}
+*/	
 	return STORAGE_OK;
-
-write_error:
-	irc_usermsg( irc, "Write error. Disk full?" );
-	close( fd );
-	
-	return STORAGE_OTHER_ERROR;
 }
 
