fixes in apply gradients