Clean up pattern matching code in AST.