refactor grid point generation to a separate function. add some comments.