completed rerewrite of grid