Moved encoding to a single operation