 extension MotivationsViewController: UICollectionViewDelegateFlowLayout {
     
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
-        let width = UIScreen.main.bounds.width - 100
-        let height = UIScreen.main.bounds.height - 200
-        
-        return CGSize(width: width, height: height)
+        let width = Float(collectionView.frame.width)
+        let cellWidth = Float(width - C.Collection.sideEdgeInset * 2)
+        
+        return CGSize(width: CGFloat(cellWidth), height: CGFloat(C.Collection.cellHeight))
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
+        return CGFloat(C.Collection.lineSpacing)
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
+        return 0.0
     }
     
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
-        let frameWidth = UIScreen.main.bounds.size.width
-        let cellWidth: CGFloat = UIScreen.main.bounds.size.width - 100
-        
-        let result = (frameWidth - cellWidth) / 2
-        
-        return UIEdgeInsets(top: 0, left: result, bottom: 0, right: result)
-    }
-    
-}
+        let topEdgeInset = CGFloat((Float(collectionView.frame.height) - C.Collection.cellHeight) / 2)
+        return UIEdgeInsets(top: topEdgeInset, left: CGFloat(C.Collection.sideEdgeInset), bottom: topEdgeInset, right: CGFloat(C.Collection.sideEdgeInset))
+    }
+    
+}

        collectionView.dataSource = self
        collectionView.delegate = self
    }

    
    func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        let pageWidth = Float(UIScreen.main.bounds.size.width - 100)
        
        let currentOffset = Float(scrollView.contentOffset.x)
        let targetOffset = Float(targetContentOffset.pointee.x)
        var newTargetOffset: Float = 0
        
        if targetOffset > currentOffset {
            newTargetOffset = ceilf(currentOffset / pageWidth) * pageWidth

        
        if newTargetOffset < 0 {
            newTargetOffset = 0
        } else if newTargetOffset > Float(scrollView.contentSize.width) {
            newTargetOffset = Float(scrollView.contentSize.width)
        }
        
        targetContentOffset.pointee.x = CGFloat(currentOffset)
        scrollView.setContentOffset(CGPoint(x: CGFloat(newTargetOffset), y: scrollView.contentOffset.y), animated: true)
    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        for cell in collectionView.visibleCells as! [MotivationCollectionViewCell] {
            self.scrollView(scrollView: scrollView, transformCell: cell)
        }
    }
    
    // MARK: - Private
    
    func scrollView(scrollView: UIScrollView, transformCell cell: MotivationCollectionViewCell) {
        let width = Float(scrollView.frame.width)
        let cellWidth = Float(width - C.Collection.sideEdgeInset * 2)
        
        let superviewCenter = scrollView.center
        let cellCenter = scrollView.convert(cell.center, to: view)
        let offset = Float(fabs(superviewCenter.x - cellCenter.x))
        
        let transformDirection = Float(cellCenter.x > superviewCenter.x ? -1.0 : 1.0)
        
        let scale = 1.0 - (C.Collection.scaleFactor * (offset / cellWidth))
        let translate = ((cellWidth - cellWidth * scale) / 2) * transformDirection
        
        var transform = CGAffineTransform.identity
        transform = transform.scaledBy(x: CGFloat(scale), y: CGFloat(scale))
        transform = transform.translatedBy(x: CGFloat(translate), y: CGFloat(0.0))

        cell.layerView.transform = transform
    }
}

