Let $f:X\rightarrow Y$ be a function from one set $X$ to another set $Y$. Show that $f(f^{-1}(S)) = S$ for every $S\subseteq Y$ if and only if $f$ is surjective. Show that $f^{-1}(f(S)) = S$ for every $S\subseteq X$ if and only if $f$ is injective.
MY ATTEMPT
If $f(f^{-1}(S)) = S$ for every $S\subseteq Y$, then $f(f^{-1}(Y)) = f(X) = Y$, thus $f$ is surjective.
Conversely, if $f$ is surjective, then, given $S\subseteq Y$, one has that \begin{align*} f(f^{-1}(S)) = f\left(f^{-1}\left(\bigcup_{s\in S}\{s\}\right)\right) = f\left(\bigcup_{s\in S}f^{-1}(\{s\})\right) = \bigcup_{s\in S}f(f^{-1}(\{s\})) = S \end{align*} This is because $f^{-1}(\{s\})$ is non-empty due to the surjectivity and $f(f^{-1}(\{s\})) = \{s\}$.
If $f$ is injective, then $f^{-1}(f(\{s\})) = \{s\}$ for every $s\in S\subseteq X$. Thus we have that \begin{equation} f^{-1}(f(S)) = f^{-1}\left(\bigcup_{s\in S}\{f(s)\}\right) = \bigcup_{s\in S}f^{-1}(\{f(s)\}) = \bigcup_{s\in S}\{s\} = S \end{equation}
Conversely, if $f^{-1}(f(S)) = S$ for every $S\subseteq X$, we can consider $\{s\}\subseteq X$ and $\{t\}\subseteq X$. Hence we have that \begin{align*} f(s) = f(t) \Longrightarrow f^{-1}(f(\{s\})) = \{s\} = \{t\} = f^{-1}(f(\{t\})) \Longrightarrow s = t \end{align*} thus $f$ is injective.
Could someone double-check my solution?