Final encoding

Dramatically simpler!