First go at indexed decoding.

Just needs a bit of a cleanup, same for the whole file really.