will have to redo, removed additional changes to be moved to other branches
corrected implementation of chi squared. Reduced still not present