Proving that a certain function is an integral of motion for a Hamiltonian 
Let $H=q_1p_1-q_2p_2-aq_1^2+bq_2^2$ (with $a,b$ constant) be a Hamiltionian. 
Show that $G=\dfrac{p_1-aq_1}{q_2}$ is a first integral (integral of motion) of this system.

According to the proposed solution, I need to show that the Poisson Bracket $[G,H] = 0$.
I used the following method, is this valid?
Other method?
The Hamiltionian equations are:
$$\dot q_1 = \dfrac{\partial H}{\partial p_1} = q_1 \qquad\qquad \dot q_2 = -p_2$$
$$\dot p_1 = -\dfrac{\partial H}{\partial q_1} = -p_1+2aq_1 \qquad\qquad \dot p_2 = q_2-2bq_2$$
Then, if $G$ is a integral of motion the total time derivative must equal zero (true?)
So:
$$\begin{align}
\dfrac{\operatorname d G}{\operatorname d t} & = \dfrac{1}{q_2^2}\left[ q_2(\dot p_1-a\dot q_1) - \dot q_2(p_1-aq_1)\right]\\
&= \ldots \text{(substitution using the Hamiltionian equations)} \\
&= 0
\end{align}$$
 A: Your solution method and the proposed one are equivalent. Integrals of motion are those functions whose total time derivative is zero (by definition), and the total time derivative of a function $G$ dependent only on coordinates is equal to the Poisson bracket: $$\begin{align*}\dot{G} &= \frac{dG}{dt}\\ & = \frac{\partial G}{\partial q_1}\dot{q_1} + \frac{\partial G}{\partial q_2}\dot{q_2} + \frac{\partial G}{\partial p_1}\dot{p_1} + \frac{\partial G}{\partial p_2}\dot{p_2}\\ &= \frac{\partial G}{\partial q_1}\frac{\partial H}{\partial p_1} + \frac{\partial G}{\partial q_2}\frac{\partial H}{\partial p_2} - \frac{\partial G}{\partial p_1}\frac{\partial H}{\partial q_1} - \frac{\partial G}{\partial p_2}\frac{\partial H}{\partial q_2}\\ &=\bigg(\frac{\partial G}{\partial q_1}\frac{\partial H}{\partial p_1} - \frac{\partial G}{\partial p_1}\frac{\partial H}{\partial q_1}\bigg) + \bigg(\frac{\partial G}{\partial q_2}\frac{\partial H}{\partial p_2}  - \frac{\partial G}{\partial p_2}\frac{\partial H}{\partial q_2}\bigg) \\& = \{G,H\}\end{align*}$$
