fix bugs due to a misuse of dynamic_cast

never dynamic_cast an object to its base class (or what you think is
its base class): use static_class in this case!