Optimized TileGrid for situations with >500 Tiles per layer, added some more comments, and cleaned up some prepro directives.