python3 compatibility and unicode problem workaround