bug fix to loss functions, adding statistical tests