Adding preparing_encoding_decoding method and refactor encoding method