Fix tree_length bug