Rewrote method matchPattern(). Have not tested it yet.