Fixed an issue where griadient def beging added multiple times