Speed up pattern matching