Redoing treesearch implementation