Actually works now and plots a figure of the fit at the end.