Added a function that recursively creates the balltree. Still some out-of-bounds problems with indices.