Fixed bugs

Fixed bugs when creating the tree for large data sets.