merged with loss_module.R