Derived distribution of a function of two random variables I am trying to derive the following problem by myself from Bertsekas "Introduction to probability"
I cannot get the CDF of the 2nd interval (Z < 1) correctly. please identify my error.

Please help to point out any wrong steps below!
The general procedure is to first find the CDF of z, $F(z)$ and then differentiate to find the PDF.
The relationship is $Z = \frac{Y}{X}$ for $ 0 \leq X \leq 1 $ and $ 0 \leq Y \leq 1 $
The 3d plot is shown below for visualization. The line $Y = X$ seperates $Z < 1$ and $Z > 1$

The range of values of $Z$ can be split into the two intervals as shown below.
Let's find the CDF for the different intervals of $Z$.
From my understanding we try to find the CDF of Z for a particular interval through the CDF of Y and CDF of X over certain intervals in Y and X.
1st Interval
$ 0\leq Z \leq 1$ when $Y \leq X$

First let's try to find the CDF of Y
$F(z) = P(\frac{Y}{X} \leq z) = P(Y \leq ZX) $
PDF of Y is uniform over interval [0,1] therefore
$P(Y \leq ZX) = \int_{0}^{zx} 1 dy = zx$
Now the CDF of Y is a function of X so we can integrate out the X to find F(z) only in terms of z.
$F(z) = \int_{0}^{1} zx dx = \frac{z}{2}$
2nd Interval
$Z > 1$ when $Y > X$
This is the tricky one and I don't understand how to find it.
First we note that Y and X are strictly between [0,1]
Therefore to satisfy $ Y = ZX$ for the interval $Z > 1$.  $X$ can only vary from $0$ to $\frac{1}{Z}$
$F(z) = P(Y \leq ZX) = \int_{0}^{zx} 1 dy =  zx$
similarly as before we integrate out the x by $ F(z) = \int_{0}^{\frac{1}{z}} zx dx = \frac{1}{2z}$
But why the CDF in the answer $1 - \frac{1}{2z}$ ?
 A: There's a bit of a misunderstanding here.  Suppose $z > 1$.  We want $\Pr[Y \le zX]$ but if $zX > 1$, this probability is $1$ and must be included.  If you wrote $$\Pr[Y \le zX] = \int_{x=0}^{1/z} \int_{y=0}^{zx} 1 \, dy \, dx,$$ you are missing this piece.  The full expression should be $$\Pr[Y \le zX] = \int_{x=0}^{1/z} \int_{y=0}^{zx} 1 \, dy \, dx + \int_{x=1/z}^1 \int_{y=0}^1 1 \, dy \, dx.$$
To make it a bit clearer, the joint density is simply $$f_{X,Y}(x,y) = \begin{cases}1 ,& 0 \le x , y \le 1 \\ 0, & \text{otherwise}.\end{cases}$$  If we want $\Pr[Y/X \le z]$ when $z > 1$, this corresponds to the trapezoidal region with vertices $(0,0)$, $(1,0)$, $(1,1)$, $(1/z, 1)$.  To see why, plot the line $Y = zX$ where $z > 1$ is the slope of the line.  This line passes through the origin and because it has slope greater than $1$, must also pass through the top edge of the unit square; specifically, it does so when $Y = 1$, so $X = 1/z$.  Then the inequality $Y/X \le z$ is satisfied for points in the square that are below this line.
Since this region is trapezoidal, we now see that if we are to integrate first with respect to $y$, we must divide the region into two subregions:  a triangular one from $x = 0$ to $x = 1/z$ with $y = 0$ to $zx$, and a rectangular one from $x = 1/z$ to $1$ and $y = 0$ to $1$.  This is precisely the integral we set up above.
However, we can save ourselves some trouble by changing the order of integration.  If we integrate with respect to $x$ first, then $$\Pr[Y \le zX] = \int_{y=0}^1 \int_{x=y/z}^1 1 \, dx \, dy = \int_{y=0}^1 1 - \frac{y}{z} \, dy = 1 - \frac{1}{2z}$$ as claimed.
