Added encode method