Fix panic: runtime error: invalid memory address or nil pointer dereference