Completed part 5. Add gradient regularization.