Added gradient computation for multiclass case