Excessive dynamic_casts are replaced to faster implementation.