Adding chi square function