Python 3 compatibility

Added support for Python 3 and fixed some PEP8 warnings.