Grid initialization and bounds checking