Move the grid creation logic to a separate file since it's hideous code.