make lossfxn a function of B