edited doug's grid.py