I know it's inefficient but it works fast enough. The problem with a single array is that I don't know how many codewords it's going to have each pixel, I could cap it but it could change the behaviour of the algorithm. I just wanted to get the implementation right first.