fixed pruning function