Trouble with a part of the prove for a scheme $X$ is integral if it is irreducible and reduced. I want to understand the prove for this property: A scheme $X$ is integral if and only if it is irreducible and reduced. 
I am having problems with the if part: Suppose that $X$ is reduced and irreducible. Let $U ⊂ X$ be an
open set and suppose that we have $f$ and $g ∈  \mathcal{O}(U)$ such that $fg = 0$.
Set $Y =  \{ x  \in U | f_x  \in  \mathcal{M}_x  \}$ and $Z =  \{ x  \in U | g_x  \in  \mathcal{M}_x  \}$, where $ \mathcal{M}_x$ is the maximal ideal of the stalk $ \mathcal{O}_{X,x}$ for each $x \in X$.
Then $Y$ and $Z$ are both closed (this is the part I don't get, why are these both closed?) and by assumption $Y  \cup Z = U$. As $X$ is
irreducible, one of $Y$ and $Z$ is the whole of $U$, say $Y$. We may assume
that $U =  \operatorname{Spec} A$ is affine. But then $f  \in A$ belongs to the intersection
of all the prime ideals of $A$, which is the zero ideal, as $A$ contains no
nilpotent elements. 
Thank you for any suggestion.
 A: They are closed in $U$. To be precise, what one does is cover $U$ by open affines, and in each affine $U_i$, $V(f|_{U_i}) = Y  \cap U_i$. This is because if the germ of $f$ was in the maximal idea of the stalk of a point $x$, then in an affine neighborhood of $x$ the ring element $f$ was in the prime $P$ corresponding to that point, $x = [P]$. So $f \in P$, i.e. $P \in V(f|_{U_i})$. 
One can then check or use the following: 
If $A$ is a subspace of $Y$, and $U_i$ is a cover of $Y$, then if $A \cap U_i$ is closed in $U_i$ for all $i$ (in the subspace topology), then $A$ is closed in $Y$. (Pf works by considering $A^c$.)
If you prefer you can assume from the beginning that $U$ is affine, and then treat this as a commutative algebra question. 
The way you can make this reduction is as follows:
If $X$ is irreducible, then every open subset of $X$ is irreducible. (The open sets are dense definition is best for this.)
To check if a stalk is integral, it suffices to prove that it is the localization of a domain. Thus, to check that $x \in X$ has integral stalk, you just need to find an affine patch around $x$ which is integral. You can begin with finding an affine patch $U \cong Spec A$.
Now for the commutative algebra:
You are given $f, g \in A$, and you know that $Spec A$ is irreducible, and $A$ is reduced. To begin with, $V(f) = Spec A$ implies that $f$ is in all prime ideals, so as $A$ is reduced, $f = 0$. So the sets $V(f) \cup V(g)$ cannot cover $A$ if $f$ and $g$ are both nonzero. Therefore, if $fg = 0$, then $V(f) \cup V(g) = V(fg) = V(0) = Spec A$, and this implies that $f$ or $g$ must be zero.
A: As being closed is a local property, we may assume that $U$ is affine. Write $U=\mathrm{spec}A$. So $f$ can be thought of as an element of $A$, and the set $Y$ consists of all prime ideals in $A$ that contain $f$. By construction of the topology, this is a closed set.
