         return val
     }
     
-    func binarySearch<T: Comparable>(a: [T], key: T) -> Int {
+    func startIndexBinarySearch<T: Comparable>(a: [T], offset: T) -> Int {
+        if a.count < 3 { return 0} // If the range is less than 2 just break here.
         var range = 0..<a.count
         var midIndex: Int = 0
         while range.startIndex < range.endIndex {
             midIndex = range.startIndex + (range.endIndex - range.startIndex) / 2
-            if midIndex + 1  >= a.count || key >= a[midIndex] && key < a[midIndex + 1] ||  a[midIndex] == key {
-                return midIndex
-            } else if a[midIndex] < key {
+            if midIndex + 1  >= a.count || offset >= a[midIndex] && offset < a[midIndex + 1] ||  a[midIndex] == offset {
+                break
+            } else if a[midIndex] < offset {
                 range.startIndex = midIndex + 1
             } else {
                 range.endIndex = midIndex

        }
    }
    
    func internalCachedCellSectionFromRectOffset(offset: CGPoint)-> Int {
        let key =  scrollDirection == .Horizontal ? offset.x : offset.y
        return binarySearch(sectionSize, key: key)
    }
    
    func sizeOfContentForSection(section: Int) -> CGFloat {

    
    /// Returns the layout attributes for all of the cells and views in the specified rectangle.
    override public func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
        let startSectionIndex = startIndexFrom(rectOrigin: rect.origin)
        
        // keep looping until there were no interception rects
        var attributes: [UICollectionViewLayoutAttributes] = []
