Two blocks, one on top of the other, with three springs I'm currently working through some questions on normal modes of oscillation and came across this question from TAMU's Physics qualifying exam (http://people.tamu.edu/~abanov/QE/CM.pdf Problem 81). The attached diagram is below and the surfaces are all frictionless:

My problem right now is with properly writing down the Lagrangian of the system. Suppose we wanted to choose the generalized coordinates of the system as $x_1$ and $x_2$, corresponding to the centre of mass of the larger mass and the smaller mass, respectively, where $x_1=x_2=0$ is the initial position of the centre of mass of the system. I think I might be confusing myself with the frame of references by which I define the position and velocity to get the Lagrangian.
For the kinetic energy part, I'm thinking that the larger mass would have $T = \frac{1}{2}m\dot{x_1}^2$, but would the smaller mass now have $T=\frac{1}{2}m(\dot{x_2}+\dot{x_1})^2$ since it is on top of the mass that is moving?
Similarly with the potential energy part, I think the larger mass is quite simple in that it has $V=\frac{1}{2}kx_1^2$. However, I'm also not sure about the smaller mass, given that it is riding on top of the larger mass, whether it would just be $V=\frac{1}{2}kx_2^2+\frac{1}{2}kx_2^2$ or whether it would be $V=\frac{1}{2}k(x_1-x_2)^2+\frac{1}{2}k(x_1-x_2)^2$ because of the relative position of $x_2$ with respect to $x_1$.
Many thanks in advanced!
 A: The kinetic energy for both $x_1$ (assume mass $m_1$ just for distinction): $\frac{1}{2}m_1 \dot x_1^2$.
The kinetic energy for both $x_2$ (assume mass $m_2$ just for distinction): $\frac{1}{2}m_2  (\dot x_2+ \dot x_1)^2$.
Potentail energy for $m_1$: $\frac{1}{2} k x_1^2$.
Potentail energy for $m_2$: $\frac{1}{2} 2 k x_2^2 = k x_2^2$.
These terms render a Lagrangian:
$$
  L = \frac{1}{2}m_1 \dot x_1^2 + \frac{1}{2}m_2  (\dot x_2+ \dot x_1)^2 -\frac{1}{2} k x_1^2 - k x_2^2.
$$
This Lagrangian leads to equation of motion by
$\frac{\partial L}{\partial x_i} - \frac{d}{dt} \frac{\partial L}{\partial \dot x_i}= 0$
For $x_1$:
$$ \tag{1}
  (m_1 + m_2) \ddot x_1 = - k_1 x_1 - m_2 \ddot x_2.  
$$
And for  $x_2$:
$$\tag{2}
  m_2 \ddot x_2 = - 2 k_2 x_2 - m_2 \ddot x_1.  
$$
These two equations are reasonable. The Eq.(1) for $x_1$ has mass $m_1+m_2$ and taking into account of the acceleration effect for $m_2$. The Eq.(2) is for $m_2$ takineg into the consideration of the fictitious force for being in the accelleration frame of $x_1$. The term $m_2 \ddot x_2$ in Eq.(1) is some surprising, but it shoud be corret after a deeper considerations.
