Corrected an error in the primitive gradient calculation