The kd tree finally seems to work, but rendering is still quite slow