cleaned up and documented some grid code