Reorganizing grid code