 		// cell which needs the least offsetCorrection value: it will mean that
 		// it's the first cell on the left of the screen which will give
 		// pagination.
-		for layoutAttribute: UICollectionViewLayoutAttributes in super.layoutAttributesForElements(in: CGRect(x: proposedContentOffset.x, y: 0, width: collectionView!.bounds.width, height: collectionView!.bounds.height))! {
-			// layoutAttributesForElements may contain all sort of layout
+		layoutAttributes.forEach { (layoutAttribute) in
+			// UICollectionViewLayoutAttributes may contain all sort of layout
 			// attributes so we need to check if it belongs to a
 			// UICollectionViewCell, otherwise logic won't work.
 			if layoutAttribute.representedElementCategory == .cell {
-				// Since UICollectionViewFlowLayout's UICollectionView comes in
-				// an Optional flavour and we will need to get it's frame size
-				// down below, it's not a bad idea to shield us from those very
-				// strange cases in which the UICollectionView won't be there
-				// (for whatever reason) and exit the loop since it is useless
-				// to calculate an offsetCorrection for a non-existent
-				// UICollectionView.
-				guard let collectionView: UICollectionView = collectionView else {
-					break
-				}
-
 				// To accurately calculate the offsetCorrection we will check
 				// only the cells contained in one half of UICollectionView's
 				// width, following the scrolling direction. The check will be

		// UICollectionView's UICollectionViewDelegate Flow Layout.
		let collectionViewInsets: CGFloat = 10.0

		// Since UICollectionViewFlowLayout proposedContentOffset coordinates
		// won't take count of any UICollectionView UIEdgeInsets values we need
		// to fix it by adding collectionViewInsets to the .x coordinate.
		//
		// Note: This will only cover horizontal scrolling and pagination, if you
		// need vertical pagination replace the .x coordinate with .y and update
		// collectionViewInsets value with the appropriate one.
		let proposedXCoordWithInsets: CGFloat = proposedContentOffset.x + collectionViewInsets

		// We now create a variable and we assign a very high CGFloat to it (a
		// big number here is needed to cover very large
		// UICollectionViewContentSize cases). This var will hold the needed
		// horizontal adjustment to make the UICollectionView paginate scroll.
		var offsetCorrection: CGFloat = .greatestFiniteMagnitude

		// Now we loop through all the different layout attributes of the

				let discardableScrollingElementsFrame: CGFloat = collectionView.contentOffset.x + (collectionView.frame.size.width / 2)

				if (layoutAttribute.center.x <= discardableScrollingElementsFrame && velocity.x > 0) || (layoutAttribute.center.x >= discardableScrollingElementsFrame && velocity.x < 0) {
					return
				}

				if abs(layoutAttribute.frame.origin.x - proposedXCoordWithInsets) < abs(offsetCorrection) {
