I think I finally figured out the 8-bit part.
The (hopefully) final update including the 3- and 8-bit code.