Clean up unnecessary casts and instance checks.