This replaces a bunch of casts with `.as_foo()` calls, and adjusts calls to the old `is_foo()` methods that now are better as `has_foo()`. Also tidied up some whitespace to be more consistent.