Added more efficient version of dynamic_cast to avoid RTTI in release versions