Code for grid relationship count - initial and tentative