fix potential crashes by checking nullptr