added regularization to gradients