 	}
 
 	override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
+		// If the UICollectionView has paginatedScroll set to false there is no
+		// need to apply any pagination logic, so we simply return the current
+		// proposedContentOffset coordinates.
 		guard paginatedScroll == true else {
+			return CGPoint(x: proposedContentOffset.x, y: 0)
+		}
+
+		// It's not a bad idea to shield us for some strange cases where the
+		// UICollectionView won't be there for any reason, since it comes in an
+		// Optional flavor. If the UICollectionView won't be available we return
+		// the current proposedContentOffset coordinates and exit.
+		guard let collectionView: UICollectionView = collectionView else {
+			return CGPoint(x: proposedContentOffset.x, y: 0)
+		}
+
+		let scannerFrame: CGRect = CGRect(x: proposedContentOffset.x,
+		                                  y: 0,
+		                                  width: collectionView.bounds.width,
+		                                  height: collectionView.bounds.height)
+
+		// If there is no UICollectionViewLayoutAttributes for the given
+		// scannerFrame there is no reason to calculate a paginated layout for
+		// it, so we the current proposedContentOffset coordinates.
+		guard let layoutAttributes: [UICollectionViewLayoutAttributes] = super.layoutAttributesForElements(in: scannerFrame) else {
 			return CGPoint(x: proposedContentOffset.x, y: 0)
 		}
 

				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) {
					continue
				}

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

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

		// Since UICollectionViewFlowLayout's 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
		// 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
