         // Call these two methods to notify that two view controllers are being removed or added to container view controller (Check Documentation)
         if automaticallyHandleAppearanceTransitions {
             oldViewController.willMove(toParentViewController: nil)
-            newViewController.willMove(toParentViewController: self)
-        }
-        
-        addChildViewController(newViewController)
+            addChildViewController(newViewController)
+        }
         
         let size = view.bounds.size
         let contentOffset = CGFloat(selectedPageIndex) * size.width

            self.setNeedsStatusBarAppearanceUpdate()
            
        }, completion: { (finished) -> Void in
            //Call these two methods to notify that two view controllers are already removed or added to container view controller (Check Documentation)
            oldViewController.removeFromParentViewController()
            
            if self.automaticallyHandleAppearanceTransitions {
                oldViewController.didMove(toParentViewController: nil)
                newViewController.didMove(toParentViewController: self)
                
                oldViewController.endAppearanceTransition()

            
            viewController.willMove(toParentViewController: nil)
            viewController.view.removeFromSuperview()
            viewController.removeFromParentViewController()
            
            if automaticallyHandleAppearanceTransitions {
                viewController.endAppearanceTransition()
