To directly image exoplanets and faint circumstellar disks, the noisy stellar halo must be suppressed to a high level. To achieve this feat, the angular differential imaging observing technique and the least-squares Locally Optimized Combination of Images (LOCI) algorithm have now become the standard in single band direct imaging observations and data reduction. With the development and commissioning of new high-order high-contrast adaptive optics equipped with integral field units, the image subtraction algorithm needs to be modified to allow the optimal use of polychromatic images, field-rotated images and archival data. A new algorithm, TLOCI (for Template LOCI), is designed to achieve this task by maximizing a companion signal-to-noise ratio instead of simply minimizing the noise as in the original LOCI algorithm. The TLOCI technique uses an input spectrum and template Point Spread Functions (PSFs, generated from unocculted and unsaturated stellar images) to optimize the reference image least-squares coefficients to minimize the planet self-subtraction, thus maximizing its throughput per wavelength, while simultaneously providing a maximum suppression of the speckle noise. The new algorithm has been developed using on-sky GPI data and has achieved impressive contrast. This paper presents the TLOCI algorithm, on-sky performance, and will discuss the challenges in recovering the planet spectrum with high fidelity.