public async Task <int> Undo() { int count = this.getChangeCount(); count += mergeForwardOld(); this.IsCancelled = true; // undoAction() just does extra things that may not be covered by the default one undoAction(); removeFromPlayerActions(); Program.Controller.RemoveActionFromHash(this); int depth = 0; // recalculate future values if (NextAction != null) { depth = await NextAction.ReCalculateNext(); } // Unlink this node var tempPrev = PrevAction; var tempNext = NextAction; if (PrevAction != null) { tempPrev.NextAction = tempNext; } if (NextAction != null) { tempNext.PrevAction = tempPrev; } Program.CurLeaderboard.InvokeChange(count); await deleteMessage(); return(depth); }