made grid search faster by not recomputing outputs that didn't change