Why is the restriction to an open subset of a regular map of projective varieties proper? On p. 59 of Basic Algebraic Geometry 1, Shafarevich makes the definition that a map $f:X\rightarrow Y$ of quasiprojective varieties is proper if it factors as
$$X\hookrightarrow\mathbb{P}^n\times Y\xrightarrow{\pi_2}Y$$
where $\hookrightarrow$ is a closed embedding and $\pi_2$ is the projection to the second factor.
Then he asserts that, for example, if $f:X\rightarrow Y$ is a regular map of projective varieties and $U\subset Y$ is open, then $f$'s restriction to $f^{-1}(U)$ is proper.
I'm having trouble seeing why this is an example. The obvious way to factor $f$ through an embedding in $\mathbb{P}^n\times U$ is to embed $f^{-1}(U)\hookrightarrow X\hookrightarrow\mathbb{P}^n$ (since $X$ is projective) on the first factor, and map by $f$ on the second factor. But this seems like it almost certainly won't be a closed embedding.
What's going on here?
Thanks in advance.
 A: Firstly, it's not true in this definition that $X$ need be projective.  (This will be true
if $Y$ is projective, but need not be true otherwise.)
Now, to see the assertion, just notice that the intersection of $X$ (thought of as a closed subset of $\mathbb P^n \times Y$ via the given closed embedding) with $\mathbb P^n \times U$ is precisely $f^{-1}(U)$, so that we may naturally regard $f^{-1}(U)$ as a closed subset of $\mathbb P^n \times U$.  In other words, we have a closed embedding 
$$f^{-1}(U) \hookrightarrow \mathbb P^n \times U,$$
whose composition with the projection to $U$ is (the restriction of $f^{-1}(U)$ of) $f$.
This is what is needed to show that $f^{-1}(U) \to U$ is proper.  (Basically, the definition 
is set-up precisely so that this sort of argument works.  More generally, the same argument will show that any base-change of $f$ along a morphism $Z \to Y$ remains proper.)
Added: It is very important here that we are restricting to an open subset of the target (or, more generally, base-changing over a map to the target).  Properness is certainly not preserved under restricting to an open subset of the source (or by composing with an arbitrary morphism to the source).  [Added just because the title of the question is a little ambiguous on this point, and so I wasn't sure whether the OP knew how important this distinction between source and target is.]
