Initial version of pattern matching