Help me understand the skipped steps regarding Hamiltonian Fluids In "Hamiltonian Fluid Dynamics" by P. J. Morrison, the author skipped the steps when doing solving the variation problem from equations 19 - 23. Can you better help me understand what he is doing?
I put a snippet of the paper below. I am mostly stuck on the second terms in 20 and 22. I don't see how the Jacobian and the density get within the derivative term. Also why $ \frac{\partial U}{\partial \rho} $ remains within the derivative because I thought he was doing chain rule. I figured he is holding $ \rho_0 $ constant because he doesn't differentiate $ \rho_0 $.

 A: Got it. The right way to think of things is that $ q(a, t) $ is a field. Then we need to take field variations. With, $ \frac{\partial \rho_0}{\partial a_\mu} = 0 $ and $ a_0 = t $.
\begin{align}
\delta S &= \int dt\ d^3a\ \left[ \rho_0 \dot{q}_i \delta \dot{q}_i - \rho_0 \left( \frac{\partial U}{\partial \rho} \delta \rho + \frac{\partial U}{\partial s} \delta s \right) \right] \\
  &= \int dt\ d^3a\ \left[ -\rho_0 \ddot{q}_i \delta q_i - \rho_0^2  \frac{\partial U}{\partial \rho} \frac{\partial \frac{1}{\mathcal{J}}}{\partial \frac{\partial q^k}{\partial a^j}} \delta \frac{\partial q^k}{\partial a^j} \right] \\
  &= \int dt\ d^3a\ \left[ -\rho_0 \ddot{q}_i \delta q_i + \frac{\rho_0^2}{\mathcal{J}^2}  \frac{\partial U}{\partial \rho} \frac{\partial \mathcal{J}}{\partial \frac{\partial q^k}{\partial a^j}} \delta \frac{\partial q^k}{\partial a^j} \right] \
\end{align}
From Equation 13,
\begin{align}
\frac{\partial}{\partial \frac{\partial q^k}{\partial a^j}} \left[ \frac{\partial q^k}{\partial a^j} A^i_k \right] &= \frac{\partial}{\partial \frac{\partial q^k}{\partial a^j}} \left[ \mathcal{J} \delta^i_j \right] \\
A^j_k &= \frac{\partial \mathcal{J}}{\partial \frac{\partial q^k}{\partial a^j}} \\
\end{align}
Thus,
\begin{align}
\delta S &= \int dt\ d^3a\ \left[ -\rho_0 \ddot{q}_i \delta q_i + \frac{\rho_0^2}{\mathcal{J}^2}  \frac{\partial U}{\partial \rho} A^j_k\ \delta \frac{\partial q^k}{\partial a^j} \right] \\
  &= \int dt\ d^3a\ \left[ -\rho_0 \ddot{q}_k -  A^j_k \frac{\partial}{\partial a^j} \left( \frac{\rho_0^2}{\mathcal{J}^2}  \frac{\partial U}{\partial \rho} \right) \right]  \delta q_k \\
0 &= \rho_0 \ddot{q}_k +  A^j_k \frac{\partial}{\partial a^j} \left( \frac{\rho_0^2}{\mathcal{J}^2}  \frac{\partial U}{\partial \rho} \right)
\end{align}
With Equation 21, 
\begin{align}
0 &= \rho_0 \ddot{q}_k +  A^j_k \frac{\partial}{\partial a^j} \left( \frac{\rho_0^2}{\mathcal{J}^2}  \frac{\partial U}{\partial \rho} \right) \\
  &= \rho \ddot{q}_k + \frac{\partial p}{\partial q_k} \\
  &= \rho \frac{d}{dt} v + \nabla p \\
  &= \rho \left( \frac{\partial v}{\partial t} + v \cdot \nabla v \right) + \nabla p
\end{align}
