adding function for pruning paths