Replace some dynamic_casts with static_casts or virtual function calls