fixed Nx/My mixup bug in grid.c