Improved gradient handling