Clean up duplicate code.
Tidy up IP chi^2 fitting stuff.