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

            
            for i in tree.indices.reverse() where tree[i].type == .Leaf{
                
                //iterate over nodes, backwards, on the correct layer
                for j in tree.indices.reverse() where (tree[j].type == .Node) && (getLayerForIndex(j) == firstNodeLayer) {
                    
                    //attach if no child yet, do child2 first because we're filling up backwards

    func setGridViews(views: [UIView]) {
        viewsToDisplay = views
    }
    
    func addGridView(view: UIView){
        viewsToDisplay.append(view)
    }
    
    func addGridViews(views: [UIView]) {
        for view in views {
            addGridView(view)
        }
    }
    
    func removeGridViewAtIndex(index: Int) {
        guard index >= 0 && index<viewsToDisplay.count else {
            print("Error: removeGridViewAtIndex called with index out of bounds, aborting")
            return
        }
        viewsToDisplay.removeAtIndex(index)
    }
    
    
    func removeLastGridView() {
        guard viewsToDisplay.count > 0 else {
            print("Error: removeLastGridView called on empty grid")
            return
        }
        viewsToDisplay.removeLast()
    }
    
    
    
    
    func pinToEdges(view: UIView) {
