treealgorithm works yay!