fix a bug on loss computation