  The Gemini Planet Imager (GPI) is an instrument designed to directly image
planets and circumstellar disks from 0.9 to 2.5 microns (the $YJHK$ infrared
bands) using high contrast adaptive optics with a lenslet-based integral field
spectrograph. We develop an extraction algorithm based on a least-squares
method to disentangle the spectra and systematic noise contributions
simultaneously. We utilize two approaches to adjust for the effect of flexure
of the GPI optics which move the position of light incident on the detector.
The first method is to iterate the extraction to achieve minimum residual and
the second is to cross-correlate the detector image with a model image in
iterative extraction steps to determine an offset. Thus far, this process has
made clear qualitative improvements to the cube extraction by reducing the
Moir\'{e} pattern. There are also improvements to the automated routines for
finding flexure offsets which are reliable to with $\sim0.5$ pixel accuracy
compared to pixel accuracy prior. Further testing and optimization will follow
before implementation into the GPI pipeline.
