Add encoding to encode function