Fixed most bugs. Should work reasonably well now.
Fix int to string cast error
Fix unicode encoding problem
Recover from encode typeerrors