refactoring and chi2