updated grid function