stopping when best result is found