Add regularization and comments to code