Fixes grid's out of bounds memory access