Moved encoding to its own module.