devel: Switched from while to do ..while
devel: Added grid search logic