Optimised fitting script, added templates to output