I recommend that you also try to derive the Euler-Lagrange equations using the method I described earlier. It would give you a deeper understanding of these things, and I also find it much easier to remember the derivation than the actual equation for some reason.