PEP8 fixes and Python 3 compatibility

I reviewed it twice, but you should review it too. I used the `pep8` and `2to3` tools.