Defining gr at the top level main as a local variable and feeding it down as needed. Additionally, the file grid had to be changed to grid_config in order to avoid conflicts between the type grid in grid_class and the module named grid. Sam compiles.