Optimizing grid search.