Comment From: sbrannen

Unfortunately many of the apply instanceof pattern matching changes had already been made on main before I merged this PR.

I have therefore repurposed this PR for the other polishing changes it contains.