Proper gradient instead of numerical gradient