refactor to work with py3