Fixing gradient vector computation