Some rearranging and grid code