change chi2 calculation + minor changes