added stop when n=n.max and criteria doesn't meet