implemented pattern validation and some performance improvment.
added pattern validation. need revice.