 	}
 	
 	func updateTree(replace parent: GeoContinent, with children: Set<GeoCountry>) {
-		worldTree.remove(value: parent.hashValue)
+		worldTree.remove(hashValue: parent.hashValue)
 		for child in children {
-			worldTree.insert(value: child.hashValue, region: child.geometry.aabb)
+			let countryBox = RegionBounds(regionHash: child.hashValue, bounds: child.geometry.aabb)
+			worldTree.insert(value: countryBox, region: countryBox.bounds)
 		}
 	}
 
 	func updateTree(replace parent: GeoCountry, with children: Set<GeoRegion>) {
-		worldTree.remove(value: parent.hashValue)
+		worldTree.remove(hashValue: parent.hashValue)
 		for child in children {
-			worldTree.insert(value: child.hashValue, region: child.geometry.aabb)
+			let regionBox = RegionBounds(regionHash: child.hashValue, bounds: child.geometry.aabb)
+			worldTree.insert(value: regionBox, region: regionBox.bounds)
 		}
 	}
 

import Foundation

class UIState {
	private var selectedRegionHash: Int = 0
	var worldTree: QuadTree!
	
	func cullWorldTree(focus: Aabb) -> Set<Int> {
		let visible = worldTree.query(search: focus)
		return visible
	}
	
	func buildWorldTree(withWorld geoWorld: GeoWorld, userState: UserState) {
		worldTree = QuadTree(minX: -180.0, minY: -90.0, maxX: 181.0, maxY: 90.0, maxDepth: 6)
		for continent in geoWorld.children {
			worldTree.insert(value: continent.hashValue, region: continent.geometry.aabb)
			if userState.placeVisited(continent) {
				for country in continent.children {
					worldTree.insert(value: country.hashValue, region: country.geometry.aabb)
					if userState.placeVisited(country) {
						for region in country.children {
							if userState.placeVisited(continent) {
								worldTree.insert(value: region.hashValue, region: region.geometry.aabb)
							}
						}
					}

}

// MARK: Debug rendering
func debugRenderTree(_ tree: QuadTree<Int>, at focus: Aabb) {
	debugQuadNode(tree.root, at: focus)
	_ = DebugRenderer.shared.addTransientQuad(for: focus, alpha: 1.0, name: "Focus", color: .red)
}

func debugQuadNode(_ node: QuadNode<Int>, at focus: Aabb) {
	if case let .Node(bounds, values, tl, tr, bl, br) = node {
		let highlight =  !( focus.minX >= bounds.maxX ||
												focus.maxX <= bounds.minX ||
