Fixed bugs in grid script