working pattern recogniton. todo create Pattern class.