Fix the problem with referring to the wrong figure.
The \caption always has to come before the \label otherwise things go haywire.