Improve PEP8 and Python 3 compliance

Thanks to @JDWarner and @ahojnnes for the input.