fix bug: calculate gradient