             return
         }
         
-        if 1 < abs(index - selectedIndex) {
-            let last = viewControllers.count - 1
-            var pos = 0
-            
-            if last == selectedIndex {
-                pos = last - 1
-            } else if 0 == selectedIndex {
-                pos = 1
-            } else {
-                pos = selectedIndex + (index > selectedIndex ? 1 : -1)
-            }
-            
-            scrollView.setContentOffset(CGPoint(x: scrollView.width * CGFloat(pos), y: 0), animated: false)
-        }
-        
         selectedIndex = index
+        
+        removeViewControllers()
         prepareViewControllers()
         layoutViewControllers()
     }


open class TabMenuController: UIViewController {
    @IBInspectable
    open var selectedIndex: Int {
        didSet {
            scrollView.setContentOffset(CGPoint(x: scrollView.width * CGFloat(selectedIndex), y: 0), animated: true)
            
            guard false == tabBar?.isAnimating else {
                return
            }
            
            tabBar?.select(at: selectedIndex)
        }
    }
    
    /// Enables and disables bouncing when swiping.
    open var isBounceEnabled: Bool {

     - Parameter position: An Int for the position of the view controller.
     */
    fileprivate func layoutViewController(at index: Int, position: Int) {
        guard 0 <= index && index < viewControllers.count else {
            return
        }
        
        viewControllers[index].view.frame = CGRect(x: CGFloat(position) * scrollView.width, y: 0, width: scrollView.width, height: scrollView.height)
    }
}

extension TabMenuController {
    /// Removes the view controllers not within the scrollView.
    fileprivate func removeViewControllers() {
        let count = viewPoolCount < viewControllers.count ? viewPoolCount : viewControllers.count
        scrollView.contentSize = CGSize(width: scrollView.width * CGFloat(count), height: scrollView.height)
        
        if 0 == selectedIndex {
            for i in count..<viewControllers.count {
                removeViewController(at: i)
            }
        } else if viewControllers.count - 1 == selectedIndex {
            for i in 0..<viewControllers.count - 2 {
                removeViewController(at: i)
            }
        } else {
            for i in 0..<selectedIndex {
                removeViewController(at: i)
            }
            
            let x = selectedIndex + 1
            
            if x < viewControllers.count {
                for i in x..<viewControllers.count {
                    removeViewController(at: i)
                }
            }
        }
    }
    
    /**
     Removes the view controller as a child view controller with
     the given index.
     - Parameter at index: An Int for the view controller position.
     */
    fileprivate func removeViewController(at index: Int) {
        let vc = viewControllers[index]
        
        guard childViewControllers.contains(vc) else {
            return
        }
        
        removeViewController(viewController: vc)
    }
    
    /**
