             //if childview is supposed to be attached, attach
             for childView in childViews {
                 if !nodeView.arrangedSubviews.contains(childView) {
+                    childView.removeFromSuperview() //remove in case it is still attached to another stackview
                     nodeView.addArrangedSubview(childView)
                 }
             }
         }
     }
-
+    
     
     
     func getLayerForIndex(index: Int) -> Int{

        for i in viewsToDisplay.indices {
            let nodeViewCount = getNodeViewCount()
            
            if (nodeViewCount + i ) > views.count - 1 { //check if view at that index exists already
                views.insert(viewsToDisplay[i], atIndex: nodeViewCount + i) //if not append
            } else {
                if views[nodeViewCount + i] != viewsToDisplay[i] { //overwrite if different

            //if subview is not supposed to be subview, remove
            for subView in nodeView.arrangedSubviews {
                if !childViews.contains(subView) {
                    subView.removeFromSuperview()
                }
            }
