     
     func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
         
+        guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
+            return nil
+        }
+        
         PageViewController.currentPage -= 1
+        
+        if PageViewController.currentPage != viewControllerIndex {
+            PageViewController.currentPage = viewControllerIndex
+        }
         
         guard PageViewController.currentPage >= 0 else {
             PageViewController.currentPage = 0
-            return nil
-        }
-        
-        guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
             return nil
         }
         

    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if PageViewController.currentPage == 0 && scrollView.contentOffset.x < scrollView.bounds.size.width {
            scrollView.contentOffset = CGPoint(x: CGFloat(scrollView.bounds.size.width), y: CGFloat(0))
        }
        else if PageViewController.currentPage == 2 && scrollView.contentOffset.x > scrollView.bounds.size.width {
            scrollView.contentOffset = CGPoint(x: CGFloat(scrollView.bounds.size.width), y: CGFloat(0))
        }
        
    }
    
    //array to reference the view controllers to page through

        dataSource = self
        
        for view: UIView in view.subviews {
            if let scrollView = view as? UIScrollView {
                scrollView.delegate = self
            }
        }
        
