implemented permutation checking and char replacement