added debugging for when the gradient fails