   }
 
   func indexPath(_ index: Int) -> (Int, Int) {
-    let section = sectionForIndex[index]
-    let item = index - sectionBeginIndex[section]
-    return (section, item)
+    let sectionIndex = sectionBeginIndex.binarySearch { $0 <= index } - 1
+    return (sectionIndex, index - sectionBeginIndex[sectionIndex])
   }
 
   open override var numberOfItems: Int {
-    return sectionForIndex.count
+    return (sectionBeginIndex.last ?? 0) + (sections.last?.numberOfItems ?? 0)
   }
 
   open override func view(at: Int) -> UIView {
     let (sectionIndex, item) = indexPath(at)
-    return currentSections[sectionIndex].view(at: item)
+    return sections[sectionIndex].view(at: item)
   }
 
   open override func update(view: UIView, at: Int) {
     let (sectionIndex, item) = indexPath(at)
-    currentSections[sectionIndex].update(view: view, at: item)
+    sections[sectionIndex].update(view: view, at: item)
   }
 
   open override func identifier(at: Int) -> String {
     let (sectionIndex, item) = indexPath(at)
-    let sectionIdentifier = currentSections[sectionIndex].identifier ?? "\(sectionIndex)"
-    return "\(sectionIdentifier)." + currentSections[sectionIndex].identifier(at: item)
+    let sectionIdentifier = sections[sectionIndex].identifier ?? "\(sectionIndex)"
+    return "\(sectionIdentifier)." + sections[sectionIndex].identifier(at: item)
   }
 
   open override func layout(collectionSize: CGSize) {
     layout.layout(
       collectionSize: collectionSize,
-      dataProvider: ArrayDataProvider(data: currentSections, identifierMapper: {
-       return $1.identifier ?? "\($0)"
-      }),
+      dataProvider: dataProvider,
       sizeProvider: { (_, data, collectionSize) in
         data.layout(collectionSize: collectionSize)
         return data.contentSize

open class CollectionComposer: BaseCollectionProvider {

  public var sections: [AnyCollectionProvider] {
    didSet {
      setNeedsReload()
    }
  }

  fileprivate var sectionBeginIndex: [Int] = []
  fileprivate var sectionForIndex: [Int] = []

  fileprivate var currentSections: [AnyCollectionProvider] = []

  public var presenter: CollectionPresenter? { didSet { setNeedsReload() } }

  public var layout: CollectionLayout<AnyCollectionProvider> {
    didSet {

    }
  }

  private var sectionBeginIndex: [Int] = []
  private var dataProvider: ArrayDataProvider<AnyCollectionProvider>

  public init(identifier: String? = nil,
              layout: CollectionLayout<AnyCollectionProvider> = FlowLayout(),
              presenter: CollectionPresenter? = nil,
              sections: [AnyCollectionProvider]) {
    self.presenter = presenter
    self.layout = layout
    self.dataProvider = ArrayDataProvider(data: sections, identifierMapper: {
      return $1.identifier ?? "\($0)"
    })
    super.init(identifier: identifier)
  }

