fixed centering bug in the grid function