fix potential bugs
fix potential bugs (Uninitialized scalar field, uninitialized pointer field, unchecked dynamic_cast)