Made a function to save the grid and clear the dirty flag.