fix a potential problem about searching for previous existance in pattern