fix for inverted gradients