Fix from #115 + unicode fix

This pull request incorporates the solution from #115 and my own fix for bad str.encode() usage (which implicitly calls decode(), thus causing a crash)