Factor out grid API.
Minor tuning refinement and removal of redundant test.