Fixed a big bug that sometimes counting of pattern frequency is not correct.