Python 2+3 compatibility with  modern Python 3 installs

Some quick refactoring, use of Py3 libraries if Python 3.

Works on Python 2 and 3.