Gradient refactoring