Fix broken tree function