added encode method