Finished calculation of gradient