Refactored gradient