Minor refactoring. Adding chi-squared.