more refactoring on the encoder/decoder