Part 4a, encode (fixme)