more elegant grid.py