Update encode method.