added pruning, large test cases passed