Tree algorithm works correctly.