improved grid search, some fixes