Made encode/decode generic