Pruning function only keeps top K