Fix panic caused by nil pointer dereference.