         super.init(coder: aDecoder)
     }
 
-//    override public func loadView() {
-//        super.loadView()
-//
-//        //view = UIView(frame: view.bounds)
-//    }
-
-
-
     override public func viewWillLayoutSubviews() {
         super.viewWillLayoutSubviews()
-
-//        pageBeforeRotation = currentPage
-//
-//        let nextPageIndexPath = NSIndexPath(forItem: pageBeforeRotation + 1, inSection: 0)
-//        let thisPageIndexPath = NSIndexPath(forItem: pageBeforeRotation, inSection: 0)
-//        let previousPageIndexPath = NSIndexPath(forItem: pageBeforeRotation - 1, inSection: 0)
-//        println("nextPageIndexPath: \(nextPageIndexPath)")
-//        println("thisPageIndexPath: \(thisPageIndexPath)")
-//        println("previousPageIndexPath: \(previousPageIndexPath)")
-//
-//        println("pageBeforeRotation: \(pageBeforeRotation)")
-//
-//        //flowLayout.itemSize = view.bounds.size
-//
-//        //flowLayout.invalidateLayout()
-//        if let currentCell = self.imageCollectionView.cellForItemAtIndexPath(nextPageIndexPath) as? SwiftPhotoGalleryCell {
-//            currentCell.configureForNewImage()
-//        }
-
-    }
-
-
+        
+        pageBeforeRotation = currentPage
+        println("pageBeforeRotation: \(pageBeforeRotation)")
+        
+        flowLayout.itemSize = view.bounds.size
+    }
+    
     override public func viewDidLayoutSubviews() {
-//        let desiredIndexPath = NSIndexPath(forItem: currentPage, inSection: 0)
-//        imageCollectionView.reloadItemsAtIndexPaths([desiredIndexPath])
-
-        imageCollectionView.reloadData()
-
-//        if let currentCell = imageCollectionView.cellForItemAtIndexPath(desiredIndexPath) as? SwiftPhotoGalleryCell {
-//            currentCell.configureForNewImage()
-//        }
-
-//        if pageBeforeRotation > 0 {
-//            imageCollectionView.scrollToItemAtIndexPath(desiredIndexPath, atScrollPosition: .CenteredHorizontally, animated: true)
-//            imageCollectionView.reloadItemsAtIndexPaths([desiredIndexPath])
-//        }
-
-    }
-
-
-//    override public func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
-//        pageBeforeRotation = currentPage
-//
-//        flowLayout.itemSize = CGSize(width: imageCollectionView.frame.height, height: imageCollectionView.frame.width)
-//        flowLayout.invalidateLayout()
-//
-//        let currentCell = imageCollectionView.cellForItemAtIndexPath(NSIndexPath(forItem: currentPage, inSection: 0))
-//        let centerOfCell = currentCell?.center ?? CGPointZero
-//        let centerInSuperViewCoord = imageCollectionView?.superview?.convertPoint(centerOfCell, fromView: imageCollectionView!)
-//        imageCollectionView.center = centerInSuperViewCoord ?? imageCollectionView.center
-//
-////        view.addSubview(currentCell!)
-////
-////        var imageCollectionViewConstraints: [NSLayoutConstraint] = []
-////        imageCollectionViewConstraints.append(NSLayoutConstraint(item: currentCell!, attribute: .Leading, relatedBy: .Equal, toItem: view, attribute: .Leading, multiplier: 1, constant: 0))
-////        imageCollectionViewConstraints.append(NSLayoutConstraint(item: currentCell!, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1, constant: 0))
-////        imageCollectionViewConstraints.append(NSLayoutConstraint(item: currentCell!, attribute: .Trailing, relatedBy: .Equal, toItem: view, attribute: .Trailing, multiplier: 1, constant: 0))
-////        imageCollectionViewConstraints.append(NSLayoutConstraint(item: currentCell!, attribute: .Bottom, relatedBy: .Equal, toItem: view, attribute: .Bottom, multiplier: 1, constant: 0))
-////
-////        view.addConstraints(imageCollectionViewConstraints)
-//
-//    }
-
-//    override public func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
-//        //imageCollectionView.reloadData()
-//        imageCollectionView.performBatchUpdates(nil, completion: nil)
-//        flowLayout.itemSize = imageCollectionView.frame.size
-//        //let desiredIndexPath = NSIndexPath(forItem: pageBeforeRotation, inSection: 0)
-//        //imageCollectionView.reloadItemsAtIndexPaths([desiredIndexPath])
-//
-////        currentCell!.removeFromSuperview()
-//
-////        let desiredIndexPath = NSIndexPath(forItem: pageBeforeRotation, inSection: 0)
-////        if let currentCell = imageCollectionView.cellForItemAtIndexPath(desiredIndexPath) as? SwiftPhotoGalleryCell {
-////            currentCell.configureForNewImage()
-////        }
-//
-//
-////        flowLayout.finalizeCollectionViewUpdates()
-//        //imageCollectionView.scrollToItemAtIndexPath(NSIndexPath(forItem: pageBeforeRotation, inSection: 0), atScrollPosition: .CenteredHorizontally, animated: false)
-//    }
-
-
-    public override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
-
-        super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
-
-        // Calculate current page to update the content offset to the correct position when the orientation changes
-        // I take a copy of the currentPage variable, as it will be incorrectly calculated once we are in the animateAlongsideTransition block
-        // Because the contentSize will already be changed to reflect the new orientation
-        let theCurrentPage = Int(currentPage)
-
-        coordinator.animateAlongsideTransition({ (context) -> Void in
-
-            let contentOffSet:CGPoint
-            contentOffSet = CGPoint(x: Int(self.imageCollectionView.bounds.size.width) * theCurrentPage, y: 0)
-
-            self.imageCollectionView.contentOffset = contentOffSet
-
-            }, completion: { (context) -> Void in
-                self.imageCollectionView.reloadData()
-        })
-        
-        flowLayout.invalidateLayout()
-        
-    }
-
-
-    public func collectionView(imageCollectionView: UICollectionView, layout flowLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
-        return imageCollectionView.bounds.size
-    }
-
+        let desiredIndexPath = NSIndexPath(forItem: pageBeforeRotation, inSection: 0)
+        
+        if pageBeforeRotation > 0 {
+            imageCollectionView.scrollToItemAtIndexPath(desiredIndexPath, atScrollPosition: .CenteredHorizontally, animated: false)
+            imageCollectionView.reloadItemsAtIndexPaths([desiredIndexPath])
+        }
+        
+        if let currentCell = imageCollectionView.cellForItemAtIndexPath(desiredIndexPath) as? SwiftPhotoGalleryCell {
+            currentCell.configureForNewImage()
+        }
+        
+    }
     
     // MARK: Lifecycle methods
 
     override public func viewDidLoad() {
         super.viewDidLoad()
-
-        //view.backgroundColor = UIColor.grayColor()
 
         setupCollectionView()
         setupPageControl()

    // MARK: UICollectionViewDelegate Methods
    
    public func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
        //let visibleIndexes = imageCollectionView.indexPathsForVisibleItems()
        
        //currentPage = visibleIndexes.first?.item ?? 0

        currentPage = getCurrentPage()


        imageView.setTranslatesAutoresizingMaskIntoConstraints(false)
        scrollView = UIScrollView(frame: frame)
        scrollView.setTranslatesAutoresizingMaskIntoConstraints(false)
        
        super.init(frame: frame)

        var scrollViewConstraints: [NSLayoutConstraint] = []
        var imageViewConstraints: [NSLayoutConstraint] = []
