fixed decode/encode methods being backward