grid search, a bit cleaner