Cache the k-d tree in Main class.