updated to double gain/offset regularization