 		func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
 			var layoutAttributes = [UICollectionViewLayoutAttributes]()
 			
+			// for each section
 			for section in 0..<sections.count {
 				let sectionIndexPath = NSIndexPath(forItem: 0, inSection: section)
 				
-				if let headerAttributes = layout.layoutAttributesForSupplementaryViewOfKind(UICollectionElementKindSectionHeader, atIndexPath: sectionIndexPath) where headerAttributes.frame.size != CGSizeZero && CGRectIntersectsRect(headerAttributes.frame, rect) {
-					layoutAttributes.append(headerAttributes)
-				}
-				
-				if let footerAttributes = layout.layoutAttributesForSupplementaryViewOfKind(UICollectionElementKindSectionFooter, atIndexPath: sectionIndexPath) where footerAttributes.frame.size != CGSizeZero && CGRectIntersectsRect(footerAttributes.frame, rect) {
-					layoutAttributes.append(footerAttributes)
+				// if a positive size header frame was computed that intersects the rect
+				if let headerFrame = layoutFrameTree.sections[section].headerFrame,
+					headerAttributes = layout.layoutAttributesForSupplementaryViewOfKind(
+						UICollectionElementKindSectionHeader,
+						atIndexPath: sectionIndexPath
+					) where headerFrame.size != CGSizeZero &&
+						CGRectIntersectsRect(headerFrame, rect) {
+							
+							headerAttributes.frame = headerFrame
+							layoutAttributes.append(headerAttributes)
+				}
+				
+				// repeat for the footer
+				if let footerFrame = layoutFrameTree.sections[section].footerFrame,
+					footerAttributes = layout.layoutAttributesForSupplementaryViewOfKind(
+						UICollectionElementKindSectionFooter,
+						atIndexPath: sectionIndexPath
+					) where footerFrame.size != CGSizeZero &&
+						CGRectIntersectsRect(footerFrame, rect) {
+							footerAttributes.frame = footerFrame
+							layoutAttributes.append(footerAttributes)
 				}
 			}
 			

			private static func computeContainerFrame(frameNodes:[FrameNodeImpl]) -> CGRect {
				var rect = CGRect(x: CGFloat.max, y: CGFloat.max, width: 0.0, height: 0.0)
				for frameNode in frameNodes {
					if frameNode.frame.origin.x < rect.origin.x {
						rect.origin.x = frameNode.frame.origin.x
					}
					// sum the origin and the width to get total width
					let frameWidth = frameNode.frame.origin.x + frameNode.frame.size.width
					// if that exceeds the rect
					if frameWidth > rect.origin.x + rect.size.width {
						// subtract the rect origin from the total width so overall width of the container now matches the overall width of the frame
						rect.size.width = frameWidth - rect.origin.x
					}
					
					if frameNode.frame.origin.y < rect.origin.y {
						rect.origin.y = frameNode.frame.origin.y
					}

					let frameHeight = frameNode.frame.origin.y + frameNode.frame.size.height
					if frameHeight > rect.origin.y + rect.size.height {
						rect.size.height = frameHeight - rect.origin.y
					}
				}
				return rect
			}

					cellFrames.append(MosaicLayoutFrameTree.SectionFrameNode.CellFrameNode(frame: cellFrame))
					// used for fast lookup of items in rect
					itemFrameForIndexPath.append((indexPath:NSIndexPath(forItem: rowIndex, inSection: sectionIndex), frame:cellFrame))
					if cellFrame.origin.y + cellFrame.size.height > sectionVerticalExtent {
						sectionVerticalExtent = cellFrame.origin.y + cellFrame.size.height
					}
				}
				
				
				var footerFrame = frameForSupplementaryViewOfKind(UICollectionElementKindSectionFooter, inSection:sectionIndex)
				footerFrame?.origin.y = sectionVerticalExtent
			
				let sectionFrameNode = MosaicLayoutFrameTree.SectionFrameNode(cells: cellFrames, headerFrame: headerFrame, footerFrame: footerFrame)
				
				sectionFrames.append(sectionFrameNode)
				// recalculate contentSize with addition of new section + footer height and section and content inset bottoms
				let newContentSize = MosaicLayoutFrameTree(sections: sectionFrames).contentSize
				contentSize = CGSizeMake(newContentSize.width, newContentSize.height  + sectionInset.bottom + contentInset.bottom)
			}
			
			layoutFrameTree = MosaicLayoutFrameTree(sections: sectionFrames)
