 			}
 
 			// If it's an error, handle it
-
+			var callbackInfo:*;
 			if ( iq.type == IQ.TYPE_ERROR)
 			{
 				dispatchError( iq.errorCondition, iq.errorMessage, iq.errorType, iq.errorCode );
-			}
-			else
-			{
 
 				// Start the callback for this IQ if one exists
 				if ( pendingIQs[iq.id] !== undefined )
 				{
 					var callbackInfo:* = pendingIQs[iq.id];
+
+					if (callbackInfo.errorFunc != null)
+					{
+						callbackInfo.errorFunc( iq );
+					}
+					pendingIQs[iq.id] = null;
+					delete pendingIQs[iq.id];
+				}
+			}
+			else
+			{
+
+				// Start the callback for this IQ if one exists
+				if ( pendingIQs[iq.id] !== undefined )
+				{
+					callbackInfo = pendingIQs[iq.id];
 
 					if (callbackInfo.methodScope && callbackInfo.methodName)
 					{

				if ( o is IQ )
				{
					var iq:IQ = o as IQ;
					if ((iq.callbackName != null && iq.callbackScope != null) || iq.callback != null)
					{
						addIQCallbackToPending( iq.id, iq.callbackName, iq.callbackScope, iq.callback );
					}
				}
				var root:XMLNode = o.getNode().parentNode;

		{
			dispatchEvent(new LoginEvent());
		}
		
		/**
		 * 
		 * @param	packet
		 */
		private function handleSessionError(packet:IQ):void
		{
			
		}

		/**
		 * @private
		 */
		protected function addIQCallbackToPending( id:String, callbackName:String, callbackScope:Object, callbackFunc:Function, errorCallbackFunc:Function ):void
		{
			pendingIQs[id] = { methodName:callbackName, methodScope:callbackScope, func:callbackFunc, errorFunc:errorCallbackFunc };
		}

		/**
