Fixed sign flipping issues w.r.t. variable batch size.