I have difficulty in understanding the transition in following statement:
$\mathbb{E}\left( X_{\tau }\right) = \sum _{k=0}^{K}\mathbb{E}[ \mathbb{E}(X_{k}|\mathscr{F}_{k})1_{\tau=k}] = \sum _{k=0}^{K}\mathbb{E}[X_K1_{\tau=k}] $
Could you please explain what property is used to replace $\mathbb{E}(X_{k}|\mathscr{F}_{k})$ by $X_K$?
Further details on are from (Bingham, Kiesel 2004). I have highlighted the part, which I cannot grasp :

Since $\{X_t\}$ is martingale we know that $E[X_K \mid \mathcal{F}_k]=X_k$.
Then, reemplacing $X_k$ we obtain
$E[X_k 1_{(\tau=k)}]=E[E[X_K \mid \mathcal{F}_k] 1_{(\tau=k)}]$. (*)
On the other hand, since $\tau$ is stopping time we have that $1_{(\tau=k)}$ is $\mathcal{F}_k$-measurable. Then , due to an elemental property of conditional expectation, we have $E[X_K \mid \mathcal{F}_k]1_{(\tau=k)}=E[X_K 1_{(\tau=k)}\mid \mathcal{F}_k]$.
In view of (*), we conclude that $E[X_k 1_{(\tau=k)}]=E[E[X_K 1_{(\tau=k)} \mid \mathcal{F}_k] ]$
Finally, due to the definition of conditional expectation $E[X_K 1_{(\tau=k)}]=E[E[X_K 1_{(\tau=k)}\mid\mathcal{F}_k]]$.
We obtain, $E[X_k 1_{(\tau=k)}]=E[X_K 1_{(\tau=k)}]$.