added encode/decode methods