modified logic for computation of gradient