Black-Scholes differential equation rewritten
I have seen that the Black-Scholes equation
$$ \frac{\partial V}{\partial t}+\frac{1}{2}\sigma^2S^2\frac{\partial^2 V}{\partial S^2}+ rS\frac{\partial V}{\partial S}-rV=0 $$
can also be written in the following form:
$$ \frac{\partial V}{\partial t}+\frac{\partial}{\partial S} \left( \frac{1}{2}\sigma^2S^2\frac{\partial V}{\partial S}\right)+\left(rS-\frac{\partial}{\partial S}\left(\frac{1}{2}\sigma^2S^2\right)\right)\frac{\partial V}{\partial S}-rV=0. $$
How are the following two terms equal?
$$ \frac{1}{2}\sigma^2S^2\frac{\partial^2 V}{\partial S^2}+ rS\frac{\partial V}{\partial S} = \frac{\partial}{\partial S} \left( \frac{1}{2}\sigma^2S^2\frac{\partial V}{\partial S}\right)+\left(rS-\frac{\partial}{\partial S}\left(\frac{1}{2}\sigma^2S^2\right)\right)\frac{\partial V}{\partial S} $$
Note that: $$ \frac{\partial}{\partial S} \left( \frac{1}{2}\sigma^2S^2\frac{\partial V}{\partial S}\right) =\sigma^2S\frac{\partial V}{\partial S}+ \frac{1}{2}\sigma^2S^2\frac{\partial^2V}{\partial S^2} $$ The first term above cancels with the second term in the second bucket of brackets.