 // MARK: - UIScrollViewDelegate
 
 extension CarouselViewController {
-
+    
     override func scrollViewDidScroll(scrollView: UIScrollView) {
         if scrollView == collectionView {
-            pageControl.frame.origin.x = (scrollView.bounds.width - pageControl.frame.width) / 2 + scrollView.contentOffset.x
-            pageControl.frame.origin.y = scrollView.bounds.height - pageControl.frame.height + scrollView.contentOffset.y - controlInsetBottom
-            pageControl.currentPage = loopedPageForPage(page)
+            updatePageControl()
         }
     }
     

    
    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView?.pagingEnabled = true
        collectionView?.showsHorizontalScrollIndicator = false
        if let layout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout {
            layout.scrollDirection = .Horizontal
            layout.minimumInteritemSpacing = 0.0
        }
        addPageControl()
        scrollToPage(0, animated: false)
    }
    
    override func viewDidLayoutSubviews() {

        scrollToPage(pageControl.currentPage, animated: true)
    }
    
    private func updatePageControl() {
        pageControl.frame.origin.x = (collectionView!.bounds.width - pageControl.frame.width) / 2 + collectionView!.contentOffset.x
        pageControl.frame.origin.y = collectionView!.bounds.height - pageControl.frame.height + collectionView!.contentOffset.y - controlInsetBottom
        pageControl.currentPage = loopedPageForPage(page)
    }
    
    private func scrollToPage(page: Int, animated: Bool) {
        let loopedPage = loopedPageForPage(page)
        let scrolledPage = loopedPage + (looping ? 1 : 0)
