added checkNumericalGradient() and related functions