Implemented new grid search algorithm.