refactor to build on Python 3