Revert "Revert "---""

This reverts commit a66a8cc229702ac6ec467466bef5f729b32deae2.
fixed dereferencing null pointer