Added some improvements in the encoding process