Fixed 2D to 1D index conversion.