refactor enc/decoder with guard method