Insert checks for finiteness of the gradient