adding functionality to check gradients