Proof of stopping theorem for bounded stopping times Let $\tau$ be a bounded stopping time and $X=X_n$ a martingale. Then $X_\tau$ is integrable and $E(X_\tau)=E(X_0)$.
I need help with the proof at discrete time, at one step I am not sure I understood, and also I am new to proving stuff so may you please check I wrote correctly every step?
Suppose $\tau$ is bounded by an integer K, we can write the expectation as:
$E(X_\tau)=E[\sum_{k=0}^KX_kI(\tau=k)] $ because thanks to the indicator the only term which survives is $E(X_\tau)$
$=\sum_{k=0}^KE[X_kI(\tau=k)] $ because of linearity of expectation
$=\sum_{k=0}^KE[E[X_K|F_k]I(\tau=k)]$ because X is martingale, then the book says also because $\{\tau=k\}\in F_k$ but I can't understand why that's important
$=\sum_{k=0}^KE[X_KI(\tau=k)]$ this is what I am not sure about: was it possible to apply like E[E[X|Y]]=E[X]? If so, why the conditions to apply that are satisfied? Thank you in advance, the rest of the proof I understood. 
 A: Argumentation I:  Since $(X_k)_{k \in \mathbb{N}}$ is a martingale, we have $$X_k = \mathbb{E}(X_K \mid \mathcal{F}_k) \qquad \text{for all} \, \, k \leq K. \tag{1}$$ Consequently, $$\mathbb{E}(X_k 1_{\{\tau=k\}}) = \mathbb{E}(\mathbb{E}(X_K \mid \mathcal{F}_k) 1_{\{\tau=k\}}).$$
In the next step, we use that $\{\tau=k\} \in \mathcal{F}_k$. In fact, $\{\tau=k\} \in \mathcal{F}_k$ implies
$$\mathbb{E}(\mathbb{E}(X_K \mid \mathcal{F}_k) 1_{\{\tau=k\}}) = \mathbb{E}(\mathbb{E}(X_K  1_{\{\tau=k\}}) \mid \mathcal{F}_k)) \tag{2}$$
(this is called pull-out). Finally, recall that for any integrable random variable $X$ and for any sub-$\sigma$-algebra $\mathcal{F}$ it holds that
$$\mathbb{E}(\mathbb{E}(X \mid \mathcal{F})) = \mathbb{E}(X).$$
Applying this in $(2)$, we get
$$\mathbb{E}(\mathbb{E}(X_K \mid \mathcal{F}_k) 1_{\{\tau=k\}}) = \mathbb{E}(X_K  1_{\{\tau=k\}}).$$
Argumentation II: Recall that $$\int_F Y \, d\mathbb{P} = \int_F X \, d\mathbb{P} \qquad \text{for all} \, \, F \in \mathcal{F} \tag{3}$$ for $Y = \mathbb{E}(X \mid \mathcal{F})$. Applying this with $X = X_K$, $\mathcal{F} = \mathcal{F}_k$ and $Y:=X_k = \mathbb{E}(X_K \mid \mathcal{F}_k)$, we get
$$\mathbb{E}(X_k 1_{\{\tau=k\}}) = \mathbb{E}(X_K 1_{\{\tau=k\}})$$
as $\{\tau=k\} \in \mathcal{F}_k$.
