Fixed encoder and tests for Python 3.3