 			removeAll();
 			try
 			{
-				var exts:Array = resultIQ.getAllExtensionsByNS( RosterExtension.NS );
-				var len:int = exts.length;
-				for (var x:int; x < len; x++){
-					var ext:RosterExtension = exts[x];
-					var newItems:Array = ext.getAllItems();
-					var eLen:int = newItems.length;
-					for( var i:int=0; i < eLen; i++ ) {
-						var item:* = newItems[ i ];
+				for each(var ext:RosterExtension in resultIQ.getAllExtensionsByNS( RosterExtension.NS )) {
+					for each(var item:* in ext.getAllItems()) {
 						//var classInfo:XML = flash.utils.describeType(item);
-						if (item is XMLStanza){
-							var groups:Array = item.getGroups();
-							var gLen:int = groups.length;
-							if( gLen > 0 ){
-								for (var j:int=0; j < gLen;j++) {
-									addRosterItem( item.jid, item.name, RosterExtension.SHOW_UNAVAILABLE, "Offline", item.getGroups()[j], item.subscription.toLowerCase(), item.askType != null ? item.askType.toLowerCase() : RosterExtension.ASK_TYPE_NONE );
-								}	
-							}else{
-								addRosterItem( item.jid, item.name, RosterExtension.SHOW_UNAVAILABLE, "Offline", "General", item.subscription.toLowerCase(), item.askType != null ? item.askType.toLowerCase() : RosterExtension.ASK_TYPE_NONE );
-							}
-						}				
+						if (!item is XMLStanza)
+							continue;
+						
+						var groups:Array = item.getGroups();
+						if(groups.length == 0)
+							groups = ["General"];
+						
+						for each(var group:String in groups) {
+							addRosterItem( item.jid, item.name, RosterExtension.SHOW_UNAVAILABLE, "Offline", group, item.subscription.toLowerCase(), item.askType != null ? item.askType.toLowerCase() : RosterExtension.ASK_TYPE_NONE );
+						}		
 					}
 				}
 				

		private function handlePresence( aPresence:Presence ):void
		{
			// Handle based on the type of the presence received
			aPresence.type = (aPresence.type == null)?(Presence.AVAILABLE_TYPE):(aPresence.type);
			switch( aPresence.type.toLowerCase() )
			{
				case Presence.SUBSCRIBE_TYPE:

					{
						var tempIQ:IQ = eventObj.iq as IQ;
						var ext:RosterExtension = tempIQ.getAllExtensionsByNS( RosterExtension.NS )[0] as RosterExtension;
						for each(var item:* in ext.getAllItems())
						{
							var i:int = getContactIndex(item.jid);
							var rosterItemVO:RosterItemVO = getContactInformation(item.jid.toLowerCase());
							var ev: RosterEvent;
							
							if (rosterItemVO)
							{
								switch (item.subscription.toLowerCase())
								{
									case RosterExtension.SUBSCRIBE_TYPE_NONE:
										ev = new RosterEvent(RosterEvent.SUBSCRIPTION_REVOCATION);
										ev.jid = item.jid;
										dispatchEvent( ev );
										break;
									
									case RosterExtension.SUBSCRIBE_TYPE_REMOVE:
										//TODO: is this the right thing to do here?
										if(i < 0)
											return; //couldn't find the contact
										ev = new RosterEvent(RosterEvent.USER_REMOVED);
										ev.data = removeItemAt(i);
										ev.jid = item.jid;
										dispatchEvent(ev);
										break;
														
									default:
										for each(var group:String in item.getGroups())
										{
											updateRosterItemSubscription(i, item.subscription.toLowerCase(), item.name, group );
										}
										break;
								}
							} 
							else if( item.subscription.toLowerCase() != RosterExtension.SUBSCRIBE_TYPE_REMOVE &&  item.subscription.toLowerCase() != RosterExtension.SUBSCRIBE_TYPE_NONE) 
							{
								// Add this item to the roster if it's not there and if the subscription type is not equal to 'remove' or 'none'
								for each(var group:String in item.getGroups())
								{
									addRosterItem( item.jid, item.name, RosterExtension.SHOW_UNAVAILABLE, "Offline", group, item.subscription.toLowerCase(), item.askType != null ? item.askType.toLowerCase() : RosterExtension.ASK_TYPE_NONE );
								}
							}
						}
					}
					catch (e:Error)
					{
