Fix dereferencing null pointer problem