updated pattern matching