Implement gradType flag to control type of gradient returned
fix bug from removal is isAveraged flag