Some fixes to dim functions and improvements to grid.

Grid is still not well tested, but coming together.