added loss condition