function that updates the grid
function that updates the grid