finding the best values for griding