             if configuration.leaveStageAnimationStyle == .zoomin
                 || configuration.leaveStageAnimationStyle == .fadeAwayAndZoomin
                 || configuration.leaveStageAnimationStyle == .blend {
-                cellSize = CGSize(width: (1+itemOffset)*topCellSize.width,
-                                  height: (1+itemOffset)*topCellSize.height)
+                cellSize = CGSize(width: (1 + itemOffset) * topCellSize.width,
+                                  height: (1 + itemOffset) * topCellSize.height)
             } else {
                 cellSize = topCellSize
             }
-        } else if itemOffset<=1 && itemOffset>0 {
-            centerX = ((width-cellWidth)/2)*(1-itemOffset)+cellWidth/2+collectionView.contentOffset.x
-            centerY = ((cellHeight/2-height)/(2))*(1-itemOffset)+height-cellHeight/2
-            cellSize = CGSize(width: (cellWidth-topCellSize.width)*itemOffset+topCellSize.width,
-                              height: (cellHeight-topCellSize.height)*itemOffset+topCellSize.height)
-        } else if itemOffset>1 {
-            centerX = collectionView.contentOffset.x+(itemOffset-0.5)*cellWidth+(itemOffset-1)*configuration.spacing
-            centerY = height-cellHeight/2
+        } else if itemOffset <= 1 && itemOffset > 0 {
+            centerX = ((width - cellWidth) / 2) * (1 - itemOffset) + cellWidth / 2 + collectionView.contentOffset.x
+            centerY = ((cellHeight / 2 - height) / 2) * (1 - itemOffset) + height - cellHeight / 2
+            cellSize = CGSize(width: (cellWidth - topCellSize.width) * itemOffset + topCellSize.width,
+                              height: (cellHeight - topCellSize.height) * itemOffset + topCellSize.height)
+        } else if itemOffset > 1 {
+            centerX = collectionView.contentOffset.x + (itemOffset - 0.5) * cellWidth + (itemOffset - 1) * configuration.spacing
+            centerY = height - cellHeight / 2
         } else {
             attributes.isHidden = true
             centerX = -width
             centerY = -height
         }
         
-        let rotateFactor = fabs(itemOffset*100).remainder(dividingBy: 100)/100
+        let rotateFactor = fabs(itemOffset * 100).remainder(dividingBy: 100) / 100
         
         switch configuration.moveAnimationStyle {
-        case .waltz where itemOffset>0:
-            attributes.transform3D =  CATransform3DRotate(attributes.transform3D, CGFloat(M_PI*2)*rotateFactor, 0, 1, 0)
-        case .somefault where itemOffset>0:
-            attributes.transform3D =  CATransform3DRotate(attributes.transform3D, CGFloat(M_PI*2)*rotateFactor, 0, 0, 1)
+        case .waltz where itemOffset > 0:
+            attributes.transform3D =  CATransform3DRotate(attributes.transform3D, CGFloat(M_PI * 2) * rotateFactor, 0, 1, 0)
+        case .somefault where itemOffset > 0:
+            attributes.transform3D =  CATransform3DRotate(attributes.transform3D, CGFloat(M_PI * 2) * rotateFactor, 0, 0, 1)
         default:
             attributes.transform3D = CATransform3DIdentity
         }

//        print("item:\(item) itemOffset:\(itemOffset) topItemIndex:\(topItemIndex)")
        
        attributes.size = cellSize
        attributes.center = CGPoint(x: centerX+configuration.offsetX,
                                    y: centerY+configuration.offsetY)
        
        return attributes
    }
    
    open override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
        guard let collectionView = collectionView else { return super.targetContentOffset(forProposedContentOffset: proposedContentOffset, withScrollingVelocity: velocity) }
        let topIndexItem = proposedContentOffset.x/configuration.cellSize.width
        let x = round(topIndexItem)*(configuration.cellSize.width)
        let y = proposedContentOffset.y
        return CGPoint(x: x, y: y)
    }

    public var configuration: CPStageLayoutConfiguration
    public var currentIndex: Int {
        if let collectionView = collectionView {
            var index = Int(round(collectionView.contentOffset.x / configuration.cellSize.width))
            
            if index>=cellCount && cellCount>0 {
                index = cellCount - 1
            }
            
            return index
