Fixed bug in kd traversal