refactored to py3 compat