Fixed jython fitting and added weighting for residual function