Adding of variables and the sorting out of the grid