         bodyLayer.position = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds))
     }
     
-    private func visitNodes(nodes : [NSString], parent : CALayer, selectable : Bool, inout depth : Int, inout marking : Set<NSString>) {
+    private func visitNodes(nodes : [NSString], parent : ViewFacade?, inout depth : Int, inout marking : Set<NSString>) {
         
         // Need to gradually increase this so that children of siblings where
         // an earlier one has a deeper hierarchy than a later one don't appear on top
         // of the children of the later one
         let currentDepth = depth
         depth = depth + 1
+        
+        let parentLayer : CALayer = parent ?? bodyLayer
         
         var zPos : CGFloat = 0.0
         for node in nodes {

                for (key, value) in record.renderingInfo.contentValues {
                    layer.contentLayer.setValue((value as? NSNull) == nil ? value : nil, forKey: key as! String)
                }
                layer.hidden = layer.contentLayer.hidden || parent.hidden
                for(key, value) in record.renderingInfo.geometryValues {
                    layer.setValue(value, forKey: key as! String)
                }
                
                layer.borderLayer.transform = layer.contentLayer.transform
                
                visitNodes(record.children as! [NSString], parent : layer, selectable : layer.selectable, depth : &depth, marking: &marking)
                if depth > 0 {
                    // Add a small fudge factor so siblings are properly ordered
                    zPos += 0.001

                layer.record = record
                marking.remove(node)
                layers[node] = layer
                parentLayer.addSublayer(layer)
                layer.selectable = record.selectable && (parent?.selectable ?? true)
                
                layer.hierarchyDepth = currentDepth
                
