Fixed out of bounds for tree search. Also fixed the memory reading violation when setting the trees.