Improve pattern matching for ids.