Merged Gunnars MSP with optimization from Vidir.