redo everything, with new calling semantics for encode and decode. this breaks everything, need to fix