Fixed gradient, and matrix shape bug for sign flipping for num abilities > 1