Fixing for python 3, added encoding for unicode