encode method done