added tail char algorithm.