 	visibleChildren = getArray visibleChildren, children.length
 
 	# get last column and last row
-	i = lastColumn = lastRow = 0
+	i = lastColumn = 0
+	lastRow = -1
 	for child, childIndex in children
 		# check visibility
 		if not child._visible or (child._layout and not child._layout._enabled)

			freeWidthSpace = 0

	if not autoHeight
		freeHeightSpace = (effectItem._height - rowSpacing * lastRow - topPadding - bottomPadding) - gridHeight
		if freeHeightSpace > 0 and rowsFillsSum > 0
			unusedFills = getCleanArray unusedFills, lastRow+1
			length = lastRow+1

		i++

	# get grid size
	gridWidth = 0
	if autoWidth or columnsFillsSum > 0 or alignH isnt 0
		for i in [0..lastColumn] by 1
			gridWidth += columnsSizes[i]

	gridHeight = 0
	if autoHeight or rowsFillsSum > 0 or alignV isnt 0
		for i in [0..lastRow] by 1
			gridHeight += rowsSizes[i]

	# expand filled cells
	if not autoWidth
		freeWidthSpace = effectItem._width - columnSpacing * lastColumn - leftPadding - rightPadding - gridWidth
		if freeWidthSpace > 0 and columnsFillsSum > 0
			unusedFills = getCleanArray unusedFills, lastColumn+1
			length = lastColumn+1
