         var fixedIndex = index
 
         // if it's infinite, i fix the index to not ask views which does not exist
-        if self.infinite == true {
+        if infinite == true {
             if index == 0 {
-                fixedIndex = self.numberOfViews-3
-            } else if (index == self.numberOfViews-1) {
+                fixedIndex = numberOfViews-3
+            } else if (index == numberOfViews-1) {
                 fixedIndex = 0
             } else {
                 fixedIndex -= 1

    // carousel view controller delegate
    public var delegate : CMLazyScrollViewControllerDelegate? {
        didSet {
            self.reload()
        }
    }

    // MARK: - PUBLIC FUNCTIONS
    // remove all views and rebuild the carousel
    public func reload() {
        if let delegate = self.delegate {

            self.pageSize = self.view.frame.size
            self.cleanArray()

            self.numberOfViews = delegate.numberOfViewControllersIn(scrollViewController: self)
            self.pageControl.numberOfPages = self.numberOfViews
            if self.infinite == true {
                self.numberOfViews += 2
            }

            let width = (self.scrollDirection == .Horizontal) ? CGFloat(self.numberOfViews)*self.pageSize.width : self.pageSize.width
            let height = (self.scrollDirection == .Horizontal) ? self.pageSize.height : CGFloat(self.numberOfViews)*self.pageSize.height
            self.scrollView.contentSize = CGSize(width: width, height: height)
            self.viewControllers = Array(repeating: nil, count: self.numberOfViews)
            self.views = Array(repeating: nil, count: self.numberOfViews)


            let x = (self.infinite == true && self.scrollDirection == .Horizontal) ? self.pageSize.width : 0
            let y = (self.infinite == true && self.scrollDirection == .Vertical) ? self.pageSize.height : 0

            self.scrollView.contentOffset = CGPoint(x: x, y: y)
            self.currentIndex = (self.infinite == true) ? 1 : 0
            self.updateCarousel()
        }
    }

    // MARK: - PRIVATE FUNCTIONS
    fileprivate func requestAndAddViewControllerAt(index : Int) {
        let fixedIndex = self.fixIndex(index: index)
        var vc : UIViewController!

        if self.viewControllers[index] != nil {
            vc = self.viewControllers[index]!
        } else {
            vc = self.delegate?.viewControllerIn(scrollViewController: self, atIndex: fixedIndex) ?? UIViewController()
        }

        // force frame to the size of a page
        vc.view.frame = CGRect(x: 0.0, y: 0.0, width: self.pageSize.width, height: self.pageSize.height)
        self.addChildViewController(vc)

        let x : CGFloat = (self.scrollDirection == .Horizontal) ? CGFloat(index)*self.pageSize.width : 0.0
        let y : CGFloat = (self.scrollDirection == .Horizontal) ? 0.0 : CGFloat(index)*self.pageSize.height
        // TODO: if i dont use a view here the constraint from the vc.view will break because of the scrollView, i tried to do some autolayout with the views i added but no success :(
        let view = UIView(frame: CGRect(x: x, y: y, width: self.pageSize.width, height: self.pageSize.height))
        view.tag = index
        view.addSubview(vc.view)

        self.scrollView.addSubview(view)
        self.views[index] = view
        self.viewControllers[index] = vc
        vc.didMove(toParentViewController: self)
    }


    override public func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
        viewControllers.removeAll()
        views.removeAll()
    }

    // MARK: - SCROLLVIEWDELEGATE

    public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        if (currentIndex-2 >= 0) {
            clearSlot(index: currentIndex-2)
        }
        if (currentIndex+2 < numberOfViews-1) {
            clearSlot(index: currentIndex+2)
        }
        scrollDelegate?.scrollViewDidEndDecelerating?(scrollView)
    }

    public func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let page = (scrollDirection == .Horizontal) ? (scrollView.contentOffset.x + (0.5 * pageSize.width)) / pageSize.width : (scrollView.contentOffset.y + (0.5 * pageSize.height)) / pageSize.height

        currentIndex = Int(page)
        pageControl.currentPage = fixIndex(index: currentIndex)

        // last element, only for infinite mode
        if (infinite == true) {
            (scrollDirection == .Horizontal) ? checkDidScrollInfiniteModeWithX(scrollView: scrollView) : checkDidScrollInfiniteModeWithY(scrollView: scrollView)
        }

        lastScrollViewOffset = scrollView.contentOffset
        scrollDelegate?.scrollViewDidScroll?(scrollView)
    }

    public func scrollViewDidZoom(_ scrollView: UIScrollView) {
        scrollDelegate?.scrollViewDidZoom?(scrollView)
    }

    public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        scrollDelegate?.scrollViewWillBeginDragging?(scrollView)
    }

    public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        self.targetContentOffset = targetContentOffset.pointee
        scrollDelegate?.scrollViewWillEndDragging?(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset)
    }

    public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        scrollDelegate?.scrollViewDidEndDragging?(scrollView, willDecelerate: decelerate)
    }

    public func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
        scrollDelegate?.scrollViewWillBeginDecelerating?(scrollView)
    }

    public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
        scrollDelegate?.scrollViewDidEndScrollingAnimation?(scrollView)
    }

    public func viewForZooming(in scrollView: UIScrollView) -> UIView? {
        return scrollDelegate?.viewForZooming?(in: scrollView)
    }

    public func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
        scrollDelegate?.scrollViewWillBeginZooming?(scrollView, with: view)
    }

    public func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
        scrollDelegate?.scrollViewDidEndZooming?(scrollView, with: view, atScale: scale)
    }

    public func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
        if let bool = scrollDelegate?.scrollViewShouldScrollToTop?(scrollView) {
            return bool
        }
        return true
    }

    public func scrollViewDidScrollToTop(_ scrollView: UIScrollView) {
        scrollDelegate?.scrollViewDidScrollToTop?(scrollView)
    }

    public func screenDidRotate() {
        pageSize = view.frame.size
        let width = (scrollDirection == .Horizontal) ? CGFloat(numberOfViews)*pageSize.width : pageSize.width
        let height = (scrollDirection == .Horizontal) ? pageSize.height : CGFloat(numberOfViews)*pageSize.height
        scrollView.contentSize = CGSize(width: width, height: height)

        for view in views {
            if let view = view {
                let index : Int = view.tag
                let x : CGFloat = (scrollDirection == .Horizontal) ? CGFloat(index)*pageSize.width : 0.0
                let y : CGFloat = (scrollDirection == .Horizontal) ? 0.0 : CGFloat(index)*pageSize.height
                view.frame = CGRect(x: x, y: y, width: pageSize.width, height: pageSize.height)
            }
        }
        setCurrentPage(newValue: currentIndex, animated: false)
    }
}

