fix bug
Robust grid size choice

I have figured out a better way to choose the best grid size. It might
not be optimal for all data, but most adaptive.