 			}
 		}
 		
-		private static function initChildren(container:DisplayObjectContainer, desiredNumber:int, type:Class):Array
+		private static function initChildren(container:DisplayObjectContainer, desiredNumber:uint, type:Class):Array
 		{
+			// remove unwanted children
+			var i:int = container.numChildren;
+			while (i-- && type && !(container.getChildAt(0) is type))
+				container.removeChildAt(i);
+			
 			// remove extra children
-			while (container.numChildren > desiredNumber)
-				container.removeChildAt(container.numChildren - 1);
+			i = container.numChildren;
+			while (i-- > desiredNumber)
+				container.removeChildAt(i);
 			
 			var result:Array = [];
-			for (var i:int = 0; i < desiredNumber; i++)
+			for (i = 0; i < desiredNumber; i++)
 			{
 				if (i < container.numChildren) // existing child
 					result.push(container.getChildAt(i));
-				else // new child
+				else if (type) // new child
 					result.push(container.addChild(new type()));
 			}
 			return result;

*/
package weave.ui
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	
	import mx.containers.Grid;
	import mx.containers.GridItem;
	import mx.containers.GridRow;
	
	[DefaultProperty("dataProvider")]
	

				for (var c:int = 0; c < gridItems.length; c++)
				{
					var gridItem:GridItem = gridItems[c] as GridItem;
					var children:Array = initChildren(gridItem, 1, generator as Class);
					gridRow.addChild(gridItem);
					var dataItem:Object = dataRow[c];
					var displayObject:DisplayObject = dataItem as DisplayObject;
					if (generator is Function)
					{
						displayObject = generator(dataItem) as DisplayObject;
					}
					else if (generator is Class)
					{
						if (!ClassUtils.classExtends(getQualifiedClassName(generator), getQualifiedClassName(Container)))
							throw new Error("If generator is a Class, it must extend Container.");
						var GeneratorClass:Class = generator as Class;
						var container:Container = (children[0] as GeneratorClass || new GeneratorClass()) as Container;
						if (container)
						{
							displayObject = container;
							container.data = dataItem;
						}
					}
					if (displayObject)
						gridItem.addChild(displayObject);
					for each (var style:String in ['horizontalAlign', 'verticalAlign'])
						gridItem.setStyle(style, grid.getStyle(style));
					
