fix nil pointer dereference bug