Added tests for the encoding package and fixed some bugs