Simplified a bit of the grid math.