change top_index to top_leaves