Fixed a bug in loss().
Updated to reflect the recent bug fixes