On pg. 27 of Peskin and Schroeder I would like to know how we get the first equality when deriving the Klein-Gordon propagator for $x^0 - y^0 = 0, \vec{x} - \vec{y} = \vec{r}$:
$$ D(x-y) = \int \frac{d^3p}{(2\pi)^3} \frac{1}{2E_p} e^{i \vec{p} \cdot \vec{r}} = \frac{2\pi}{(2\pi)^3} \int_{0}^{\infty} dp \frac{p^2}{2 E_p} \frac{e^{ipr} - e^{-ipr}}{ipr} $$
The subsequent contour integral (2.52) makes sense but I'm a little confused about the derivation to get there from (2.50).
Why we are integrating only the imaginary part of $e^{ipr}$ and why the factor $ipr$ in the denominator?