Re-corrected sign of direction gradient calculation