add gradient checking code