Fix duplicated encoding problem

Now before encoding, the data is checked to see if it's already encoded.
Organizing package