various PY3 compatibility fixes