This question is about the proof of the Collection Schema (6.5) in Jech's Set Theory, 3rd Edition:
$\forall X \exists Y \, (\forall u \in X) [\exists v \varphi(u, v, p) \implies (\exists v \in Y) \varphi(u, v, p)]$
I understand that Jech's set
\begin{equation} Y \triangleq \cup_{u \in X} \hat{C}_u, \quad C_u \triangleq \{v: \varphi(u, v, p)\} \end{equation}
will do, but I don't quite see why $Y$ is a set. Certainly, as Jech continues to state,
\begin{equation} v \in Y \Leftrightarrow (\forall u \in X) (\varphi(u, v, p) \text{ and } \forall{z} (\varphi(u, z, p) \implies \text{rank}(v) \leq \text{rank}(z)), \end{equation}
which is very reminiscent of the statement of the Replacement Schema, but I don't quite see how to apply it. More precisely, I believe it would suffice to prove that
\begin{equation} \psi(u, v, p) \triangleq \varphi(u, v, p) \text{ and } \forall{z} (\varphi(u, z, p) \implies \text{rank}(v) \leq \text{rank}(z)) \end{equation}
satisfies
\begin{equation} \psi(u, v, p) \text{ and } \psi(u, w, p) \implies v = w, \end{equation}
but I don't know how. By the rank condition we certainly must have
\begin{equation} \text{rank}(v) = \text{rank}(w) \implies v \notin w \text{ and } w \notin v \end{equation}
but that doesn't lead to the desired conclusion. Hence my question: Am I on the right track, and if so, how do I wrap this up, and if not, how do I show that $Y$ is a set?
$Y=\bigcup_{u\in X}\hat{C}_u=\bigcup\{\hat{C}_u:u\in X\}$. Now we need a set $A$ conataining those $\hat{C}_u$ so that $Y=\bigcup\{\hat{C}_u\in A:u\in X\}$ is a set. But such $A$ exists by the class function $u\mapsto \hat{C}_u$ and Replacement Axiom.