added regularization code