fix for grid dimensions greater than 2^10