Initial implementation of encoding.