added in additional quit condition of correct permutation achieved