Rather messy way of keeping the 2d array processing.
Make things a bit cleaner, possibly.