Added loss computation.