Encode function done