fixed bug for least margin