thread pruning code refactory