Added option to calculate numerical gradient.