PEP8 fixes and 2to3 fixes to make it compatible with Python 3