add better pattern matching