You should only compute median patristic distance once, and store that value in the clade. This way finding groupings for more than one percentile threshold will be much faster.